From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 3286 invoked from network); 22 Jun 1998 18:09:49 -0000 Received: from canoe.roc.servtech.com (HELO canoe.xcski.com) (ptomblin@204.181.4.141) by mail2.redhat.com with SMTP; 22 Jun 1998 18:09:49 -0000 Received: (from ptomblin@localhost) by canoe.xcski.com (8.8.7/8.8.7) id OAA05049; Mon, 22 Jun 1998 14:09:41 -0400 Message-ID: <19980622140940.A4564@xcski.com> Date: Mon, 22 Jun 1998 14:09:40 -0400 From: Paul Tomblin To: axp-list@redhat.com Subject: Re: Making programs 64 bit clean References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.91.1 In-Reply-To: ; from Tim Jenkins on Mon, Jun 22, 1998 at 11:36:05AM -0400 Quoting Tim Jenkins (tim@rnaworld.princeton.edu): > > I have several programs which cast pointers to ints, which I am hoping to > clean up. It appears that if I redefine the integer variables as longs > and then cast the pointers to longs, I am converting a 64 bit pointer to a > 64 bit long, rather than a 64 bit pointer to a 32 bit int. > e.g. According to (my memory of) the ANSI standard, converting from a pointer to an int is not safe. Period. If you want to be safe (i.e portable), use a void* as your data type to store pointers, not ints or longs. One way to do this would be typedef union int_or_ptr { long intval; void* ptrval; } int_or_ptr_t; int_or_ptr_t var; var.ptrval = some_pointer; or var.intval = 12; It would then be up to you to make sure you only used var.ptrval when you'd stored a pointer then, and use var.intval when you'd stored one of the integral data types. -- Paul Tomblin, ptomblin@xcski.com. "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" - Ernst Jan Plugge