gpsd-dev
[Top][All Lists]
Advanced

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

Re: [gpsd-dev] build failure, again, due to endian.h issues


From: Beat Bolli
Subject: Re: [gpsd-dev] build failure, again, due to endian.h issues
Date: Wed, 06 Nov 2013 13:39:46 +0100
User-agent: Roundcube Webmail/0.7.2

On 2013-11-06 02:48, Eric S. Raymond wrote:

#define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)

I can't imagine that this would produce correct results at compile time.

Later in the patch:

+#ifndef IS_BIGENDIAN /* little-endian, like x86 */

This is never true, because the macro is always defined. The #else clause for the big-endian case is completely missing.

The right way would be

# if !IS_BIGENDIAN

but this expression is not a compile-time constant.

From GCC's CPP docs http://gcc.gnu.org/onlinedocs/gcc-2.95.2/cpp_1.html#SEC32

The '#if' directive in its simplest form consists of

    #if expression
    controlled text
    #endif /* expression */

expression is a C expression of integer type, subject to stringent restrictions. It may contain

    Integer constants, which are all regarded as long or unsigned long.

    Character constants ... .

Arithmetic operators for addition, subtraction, multiplication, division, bitwise operations, shifts, comparisons, and logical operations (`&&' and `||').

    Identifiers that are not macros, which are all treated as zero(!).

    Macro calls.

No mention of string constants, casts or pointer dereferencing.

I think this goes straight to the top of my "creative abuse of the
preprocessor" list.  Wonderful, isn't it?  Thank StackOverflow.

Maybe not...

Beat
--
mail: echo '<address@hidden>' | tr -d '[A-S]'
pgp: 0x506A903A; 49D5 794A EA77 F907 764F  D89E 304B 93CF 506A 903A
gsm: 4.7.7.6.0.7.7.9.7.1.4.e164.arpa
icbm: 47.0452 N, 7.2715 E
http: drbeat.li

"It takes love over gold, and mind over matter" -- Dire Straits



reply via email to

[Prev in Thread] Current Thread [Next in Thread]