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 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.
--apb (Alan Barrett)
Home |
Main Index |
Thread Index |
Old Index