X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F2568D1B1A5 for ; Thu, 10 Jun 2004 12:04:19 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71740-02 for ; Thu, 10 Jun 2004 15:04:17 +0000 (GMT) Received: from smtp-out4.xs4all.nl (smtp-out4.xs4all.nl [194.109.24.5]) by svr1.postgresql.org (Postfix) with ESMTP id E60CFD1B192 for ; Thu, 10 Jun 2004 12:04:15 -0300 (ADT) Received: from xs1.xs4all.nl (xs1.xs4all.nl [194.109.21.2]) by smtp-out4.xs4all.nl (8.12.10/8.12.10) with ESMTP id i5AF4C34063240; Thu, 10 Jun 2004 17:04:12 +0200 (CEST) Received: from xs1.xs4all.nl (jtv@localhost.xs4all.nl [127.0.0.1]) by xs1.xs4all.nl (8.12.10/8.12.10) with ESMTP id i5AF4Cfr013752; Thu, 10 Jun 2004 17:04:12 +0200 (CEST) (envelope-from jtv@xs4all.nl) Received: (from jtv@localhost) by xs1.xs4all.nl (8.12.10/8.12.9/Submit) id i5AF4COt013751; Thu, 10 Jun 2004 17:04:12 +0200 (CEST) (envelope-from jtv) Date: Thu, 10 Jun 2004 17:04:12 +0200 From: "Jeroen T. Vermeulen" To: Stephane Raimbault Cc: pgsql-interfaces@postgresql.org Subject: Re: libpq 7.4 and binary cursor Message-ID: <20040610150411.GD27490@xs4all.nl> Mail-Followup-To: Stephane Raimbault , pgsql-interfaces@postgresql.org References: <1086877827.4646.22.camel@picasso.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1086877827.4646.22.camel@picasso.lan> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/28 X-Sequence-Number: 4956 On Thu, Jun 10, 2004 at 04:30:27PM +0200, Stephane Raimbault wrote: > union { > double d; > int64_t i64; > } swap; > uint32_t tab_uint32[2]; [...] > /* Fusion */ > swap.i64 = tab_uint32[0]; > swap.i64 <<= 32; > swap.i64 |= tab_uint32[1]; > > /* Cast */ > return swap.d; This trick may work on some compilers and/or platforms, but it's not correct C. The language does not guarantee that the members of a union will be allocated in the exact same address, or even that they will overlap. What if it registerizes swap.d and/or swap.i64? It may even recognize one of the two as uninitialized, and the other as a dead value. That will get you very compact code, but not the effect you want. To see how it may go wrong, imagine your compiler implemented "union" as "#define union struct". I think this is all described in the C FAQ, BTW. Jeroen