Question

What is the purpose of this block in stdint.h (from newlib)?

#if defined(__GNUC__) && \
  ( (__GNUC__ >= 4) || \
    ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) )
/* gcc > 3.2 implicitly defines the values we are interested */
#define __STDINT_EXP(x) __##x##__

This macro is used later in the header for integer comparison but I'm not sure how it is supposed to evaluate. For example:

#if __STDINT_EXP(LONG_MAX) > 0x7fffffff
Was it helpful?

Solution

## is the cpp (C Preprocessor) operator to concatenate tokens, ie.

#if __STDIN_EXP(LONG_MAX) > 0x7fffffff

evaluates to

#if __LONG_MAX__ > 0x7fffffff

in the first step.

OTHER TIPS

The ## operator means "concatenate" to the C preprocessor, so that line is equivalent to:

#if __LONG_MAX__ > 0x7fffffff

If you really want to know what happens on a given machine, run it through the preprocessor and find out.

In the preprocessor ## concatenates two pieces of text into one larger token. This particular macro slaps underscores on each side of an identifier, so if you are using gcc 3.2 or later this:

#if __STDINT_EXP(LONG_MAX) > 0x7fffffff

Turns into this:

#if __LONG_MAX__ > 0x7fffffff
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top