Hi I'm currently doing a project in my free time. One problem I ran into
is that things like short, int, and long all have different meanings as to
size on different platforms.
In this program it's pretty important that some values only be 16-bits in
length. Is there a way to do this and make it portable?
Thanks in advance,
JB
As at least one other poster suggested, do a Google search for the C
standard <stdint.h> header. Now others have pointed out that this was
added in the 1999 update to the C language standard, and is not
actually part of the C++ standard at all, and they are correct but
somewhat short-sighted.
But without a doubt it will be added to the next major update to the
C++ standard, probably as both <stdint.h> and <cstdint.h>. And right
now, quite a few compilers supply this header already, and it works
when they compile C++ programs as well as when compiling C programs.
Even if you can't find one already put together for your
implementation, you should either be able to write one from scratch or
find one similar enough that you can modify it.
Assuming that your C++ implementation provides 2's complement integer
types with widths of exactly 8, 16, and 32 bits, and I'll bet it does,
you can write your own <stdint.h> header that will be 100% C++
standard conforming except for the 64 bit integer types.
It's not that hard at all. I've done it for several C and C++
compilers.