Friday, July 10, 2009

Limits in stdint.h

I've recently had problems with compiling my code that used the numeric limits defined in stdint.h, UINT64_MAX in particular. The error I was getting was


error: ‘UINT64_MAX’ was not declared in this scope

What I didn't know is that simply including stdint.h wasn't enough. The macro __STDC_LIMIT_MACROS has to be defined before the point where stdint.h is included, otherwise the limits are not defined. The best way of defining this macro, IMHO, is by compiling with -D__STDC_LIMIT_MACROS, instead of manually defining the macro somewhere in code. Hope this post will save someone a few minutes (hours?) if they run into similar problems.





1 comment:

Greg Hale said...

YES. Thank you. You just saved me minutes (hours?). I was about to give up on __STDC_LIMIT_MACROS b/c adding it didn't seem to help. But the -D compile flag works. I must be including stdint.h somewhere earlier than I expected I guess. Anyway thanks for your post!