From: Daniel Berger Date: 2005-12-06T04:21:37+09:00 Subject: Re: Determining endianness in extconf.rb Aaron Patterson wrote: > Hi. Hopefully this is the right list for this question! > > I am writing an extension for Ruby in C, and I need to determine > the endianness of the machine and set a flag when I compile. What is > the best way to go about this? I've seen examples of determining > endianness but I don't know how to set the flag in extconf.rb > > Any help would be greatly appreciated. Thank you! > > --Aaron > > Modify $CFLAGS or $CPPFLAGS directly: # extconf.rb if [1].pack("I") == [1].pack("N") $CFLAGS += " -DBIG_ENDIAN" # note the leading space end /* In your C code somewhere */ #ifdef BIG_ENDIAN /* Do something */ #endif Regards, Dan