tech-pkg archive

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

Re: macro expansion and types in <sys/types.h>



On Sep 6, 2014, at 4:32 AM, Alan Barrett wrote:

> On Thu, 04 Sep 2014, Brook Milligan wrote:
>> #ifndef uint16_t
>> typedef __uint16_t      uint16_t;
>> #define uint16_t        __uint16_t
>> #endif
> 
> It's allowed for a macro to be #define'd as itself[*].  Then testing it
> with #ifdef works, but expanding it doesn't change anything.
> 
> So, we could rewrite the above code as follows:
> 
>       #ifndef uint16_t
>       typedef __uint16_t uint16_t;
>       #define uint16_t   uint16_t
>       #endif
> 
> [*] ISO C99 section 6.10.3.4 [...] If the name of the macro being replaced is 
> found during this scan of the replacement list [...], it is not replaced. 
> Furthermore, if any nested replacements encounter the name of the macro being 
> replaced, it is not replaced.

If we were to do this, I believe it would solve the problem I am currently 
having as the "public" identifiers, e.g., uint16_t, wouldn't be replaced.  It 
also seems like many (all?) uses of __unit16_t would do the right thing.  
Perhaps those that don't are errors anyway, because __uint16_t and the like are 
implementation defined?

What are the implications of making a change like this?

Cheers,
Brook



Home | Main Index | Thread Index | Old Index