is there a namespace alias I need to use in order to reference the fields in stdint.h?
I included stdint.h in a program I'm using, and I'm trying to set a variable like this.
constint MAX_SMALL = UINT8_MAX;
This doesn't compile though. It tells me UINT8_MAX was not declared in this scope. I guess I don't understand how it could not be unless I need to be using a special namespace.
Try defining __STDC_LIMIT_MACROS in the preprocessor options maybe?
Edit :
In an other stdint.h for a DSP, i found this :
1 2 3 4 5
/*
According to footnotes in the 1999 C standard, "C++ implementations
should define these macros only when __STDC_LIMIT_MACROS is defined
before <stdint.h> is included."
*/
You can't just copy system header files around. Either your environment supports it or it doesn't. If it doesn't you can make up definitions that are right for your environment.
When you copy system files, you're likely to get constants that are not correct for your environment.
So I ended up having to do the define just like bartoli said. The one kicker was I had to do the define at the very top of my program, because there were other files that specifically undefined it before that unless I put it there.
I now moved it in as one of my CPPFLAGS in the overall Makefile to make sure it gets included all the time.
Dealing with these things in a portable way always gives me pause for thought.
As a rule, I tend to put such systems specific things in a file, say defs.h. You then include defs.h first. If you're using a stdafx.h, it'd go in there.
The code might look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifdef _MSC_VER
#if _MSC_VER <= 1500
// No stdint
#ifndef STDINT_TYPES
typedefunsignedshort uint16_t;
typedefunsignedlong uint32_t;
// ... other stdint types
#define STDINT_TYPES
#endif
// No nullptr
#ifndef NULLPTR
#define nullptr 0
#define NULLPTR
#endif
// ... other defines
#endif
#endif