From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Greg Troxel Newsgroups: gmane.lisp.guile.user Subject: Re: Passing C pointers through guile Date: Wed, 23 Jul 2008 07:19:25 -0400 Message-ID: References: <85E93FB6-A50A-4A6A-8DAB-7ACEE47B3928@raeburn.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1216811988 12953 80.91.229.12 (23 Jul 2008 11:19:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Jul 2008 11:19:48 +0000 (UTC) Cc: guile-user@gnu.org, "Kjetil S. Matheussen" To: Ken Raeburn Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jul 23 13:20:36 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KLcOT-0004aX-Eg for guile-user@m.gmane.org; Wed, 23 Jul 2008 13:20:29 +0200 Original-Received: from localhost ([127.0.0.1]:43555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KLcNZ-0005SV-UI for guile-user@m.gmane.org; Wed, 23 Jul 2008 07:19:33 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KLcNV-0005PZ-0P for guile-user@gnu.org; Wed, 23 Jul 2008 07:19:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KLcNT-0005PG-7F for guile-user@gnu.org; Wed, 23 Jul 2008 07:19:28 -0400 Original-Received: from [199.232.76.173] (port=39206 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KLcNT-0005PD-1N for guile-user@gnu.org; Wed, 23 Jul 2008 07:19:27 -0400 Original-Received: from fnord.ir.bbn.com ([192.1.100.210]:58638) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KLcNS-0007hY-Ro for guile-user@gnu.org; Wed, 23 Jul 2008 07:19:26 -0400 Original-Received: by fnord.ir.bbn.com (Postfix, from userid 10853) id EC2335339; Wed, 23 Jul 2008 07:19:25 -0400 (EDT) X-Hashcash: 1:20:080723:guile-user@gnu.org::1lQLeSTO24Q9+/Sh:00000000000000000000000000000000000000000001/p3 X-Hashcash: 1:20:080723:raeburn@raeburn.org::cnTmdo5RsGIfZ64v:0000000000000000000000000000000000000000001/PZ X-Hashcash: 1:20:080723:k.s.matheussen@notam02.no::cnTmdo5RsGIfZ64v:0000000000000000000000000000000000002xPw In-Reply-To: <85E93FB6-A50A-4A6A-8DAB-7ACEE47B3928@raeburn.org> (Ken Raeburn's message of "Thu, 10 Jul 2008 11:11:14 -0400") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.1 (berkeley-unix) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6692 Archived-At: Ken Raeburn writes: > On Jul 9, 2008, at 12:55, Kjetil S. Matheussen wrote: >> On Wed, 9 Jul 2008, Greg Troxel wrote: >>> Does C guarantee that pointers fit in unsigned long? >> I don't know. But in practice: Yes. > > According to various sources, 64-bit Windows uses an LLP64 model -- > meaning long is 32 bits, long long and pointers are 64 bits. So, no. I believe this is correct. I have been the 64-bit portability weenie on a large project at work, and been railing against int/* assignment. The overwhelming consensus among those of us that have actually dealt with making programs run on non-ILP32 machines is that int/* assignments are just plain wrong. > Near as I can tell, C99 does not require that there be *any* integral > type large enough to hold a pointer value (6.3.2.3 paragraph 6); and > specifically, uintptr_t and intptr_t are optional types. However, I > expect any C99 implementation we're likely to run across will have > such a type, and will define [u]intptr_t. I don't have a copy of the > C89 spec handy, though, and unfortunately that's where most compilers > are these days. My recent experience is that decent compilers are now essentially C99, and that Microsoft compilers are mostly C99 with a a few defects. Our strategy has been to patch around the defective compilers by defining the things we need somewhat like: #if defined(LOSING_COMPILER_A) #ifdef i386 typedef unsigned lont uintptr_t; #else #error DEFINE uintptr_t for yoru platfrom #endif #endif and then just rely on the C99 definition. Surprising little fixup has been needed. > In practice, it's also probably safe to use unsigned long long (or > whatever Windows calls it) on the platforms that have it, and unsigned > long on those that don't. But testing compiler properties in autoconf > and then using them in your installed headers may tie you to a > particular compiler when more than one may be available (e.g., > vendor's compiler and gcc). If we have to store a pointer we should just use void *. I see Ken's point about testing, but that quickly leads to madness as he notes.