Berger, Daniel wrote:
>>-----Original Message-----
>>From: Joe Van Dyk [mailto:joevandyk / gmail.com] 
>>Sent: Monday, July 25, 2005 12:24 PM
>>To: ruby-talk ML
>>Subject: Ruby extensions on 64 bit linux
>>
>>
>>http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/149446
>> makes me wonder, when writing C extensions, are there 
>>anything I should be watching out for when intending the code 
>>to be run on a 64 bit OS?
>>
>>Thanks,
>>Joe
> 
> 
> * Don't assume a pointer and an int are the same size
> * Don't make assumptions about the relative size of variable types
> * Be wary of sign extension problems
> * Use pointer arithmetic rather than address arithmetic
> * Never cast malloc
> * Explicitly include header files (-Wall will warn you about implicit
> declarations)
> * Watch out for data truncation, e.g. passing a size_t to something that
> expects an int.
> * Pack (align) your data structures as tightly as possible

Nice list.  I would only possibly take exception to this one. Since 
there is no standard way to pack C structs, I'd prefer to simply say 
don't make any assumptions about how the compiler will layout structs. 
The only reason this matters usually is when you want to serialize or 
deserialize a struct, and you take the shortcut of just writing/reading 
the whole struct as a single block instead of handling each field 
individually.

Adam

> * Watch out for data loss in constant expressions
> * Use %p in your (s)printf's as appropriate
> * Use #ifdef _LP64 as needed (or is that Solaris only?)
> 
> Regards,
> 
> Dan
> 
> 
>