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.