Paulo Matos wrote: > > Ulrich Eckhardt wrote: >> Paulo Matos wrote: >> > I'd like to have access to 64 bits. I think unsigned long long is 64 >> > bits in g++ although I'm not sure. Is there a way to know which type is >> > 64 bits long or not? >> >> #include <stdint.h> and use uint64_t. On systems that lack that header, >> <inttypes.h> might provide some replacement. In any case work with a >> typedef that shows that you want 64 bits. >> > > Thanks for the tip! :) > >> > Still, even if I know that unsigned long long is 64 bits long, how can >> > I know that it will occupy only two registers in a 32bit PC, or 1 >> > register in a 64bit PC? Is there a way to make sure a 64 bit value, be >> > it an unsigned long long or a unsigned char v[8] to be kept on 2 >> > registers or 1 in 32 bit or 64 bit PC respectively? >> >> Generally, you can't know that portably in C++. Why do you think you need >> to? >> > > I don't need to... I just would like to know that... curiosity. Still, > I know it is not possibly in portable C++ but that's why I posted here. > Any g++ specific way?
You can get a clue with 'sizeof' but only a clue bearing in mind sizeof(char)=1 even if (say) char is (ahem) 17bits. Mostly though, for us, sizeof(char) is 1 and 8bits. It's actually a tricky question because the question has to be asked right in order to give a correct answer. If you want an unsigned 64bit int then even if you do not have access to stdint you can declare your own "uint64" (or whatever you want to call it) in terms of what you do know (with caveat that given compiler allows such a type). The question comes back on itself because you have to know what a specific compiler does before you can declare it. EG: In 16bit days there was a time when some compilers 'int' would be 16bit whilst other compilers were 32bit. In order to declare a "uint16" one would have to know the compiler because first would want "typedef unsigned int uint16" and second would want "typedef unsigned short". Having said that, chances are both would have "short" as 16bit so the problem went away with a bit of thought. Best approach is not to worry about it. Provided your datatype can cope with the range of values you desire then you'll be fine - your 32bit code will work fine on 64bit. _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus