You are not logged in.
Pages: 1
I have a template class that hold numeric data (for simplicity think of it as a vector). When I do addition, I want to have the type promotion handled automatically.
The only problem is in the case of adding an unsigned int and a long. On 32 bit computer, this should resulting in a unsigned int. On an 64 bit computer it will result in a long.
My question is, how can I tell within my code whether it is being compiled on a 32 or 64 bit cpu?
Offline
limits.h and inttypes.h use
#if __WORDSIZE == 64
to check for 32/64 bit systems on build time. The definition is in bits/wordsize.h where a check for
#if defined __x86_64__
is done.
The first variant is most probably more portable (think e.g. of PPC64), but I believe both are limited to gcc.
Last edited by wuischke (2008-03-24 07:05:04)
Offline
Thanks for the ideas. It appears that the "__WORDSIZE" definition is a glibc construct. I see "__x86_64__" is used in libpng and mono so perhaps that is a gcc define. Going to look into this now.
Offline
Well, I just found this command to list all gcc internal definitions
echo "" | g++ -E -dM -x c - | sort | less
i386 (and variants __i386 and __i386__) are defined by gcc on linux and in mingw on windows. Now I have to decide what platforms I would like support...
Offline
Pages: 1