I have code like the following (Mixed C/C++ application)
#include <stdint.h>
#define BUFFER_SIZE UINT16_MAX
I was expecting BUFFER_SIZE to be (65535) like UINT16_MAX is defined in stdint.h but instead the compiler complains the UINT16_MAX was not defined. Obviously the macro expansion isn't happening as I would like.
I could just define it myself to (65535) but would like to know why this doesn't work.
Response to a couple comments:
My compiler does support the
uint16_ttype andUINT16_MAXis defined in stdint.hOne person mentioned defining
__STDC_LIMIT_MACROS- I have tried defining this before including stdint.h to no effect.
ANSWER
So it was the __STDC_LIMIT_MACROS but more complicated.
- The #define was in a header file (which included stdint.h)
- I had #define
__STDC_LIMIT_MACROSin this file prior to including stdint.h - I included that header file in another source file. This other source file also #include
stdint.h and did so prior to including my header. Therefore when stdint.h was first included
__STDC_LIMIT_MACROSwas not defined
My solution was just to add -D__STDC_LIMIT_MACROS to my compiler arguments.
limits.h- VoidPointerUINT_MAXis defined inlimits.h, butUINT16_MAXis defined instdint.h(if the implementation provides an exact 16-bit unsigned type). - Pete Beckeruint16_t? That's not required to exist. - Pete BeckerNwith the number of bits. - Pete Becker