[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: endianness (was Re: sysadmin qualifications (Re: apt-get vs. aptitude))





Le 17.10.2013 18:17, Jonathan Dowland a écrit :
On Thu, Oct 17, 2013 at 05:29:33PM +0200,
berenger.morel@neutralite.org wrote:
Speaking about endianness, it really is hard to manage:

void myfunction( ... )
{
#ifdef BIG_ENDIAN
move_bytes_in_a_specific_order
#else
move_bytes_in_the_other_specific_order
#endif
}

Bad way to manage endian in C. Better to have branching based on C
itself (rather than preprocessor), otherwise you run the risk of never
testing code outside the branch your dev machine(s) match.
<snip>
Or similar. The test will likely be compiled out as a no-op anyway with
decent compilers (GCC: yes; Sun Workshop: no.)

I do not understand why?
In both cases with "decent compilers" it is solved at compile-time, so what is the problem with preprocessor here? In case BIG_ENDIAN is not defined but should be?


Reply to: