World: r3wp
[Core] Discuss core issues
older | first |
Andreas 22-Feb-2012 [2904x4] | The C standard is (as always) very vague and doesn't specify a particular storage size. I think it just defines that _Bool must be able to hold 0 and 1. |
So when encountering a "bool", one really has to ask what kind of bool that is. More often than not, it won't be a C99 _Bool and will actually be int-sized. | |
If it is a C99 _Bool, it will typically be char-sized, though. | |
And I think Pekr really has a different case, because he's trying to use a C++ lib. C++ really has a bool, and I think it's char-sized (but I don't know whether that's impl-specific in C++ or defined in the C++ standard). | |
Ladislav 23-Feb-2012 [2908x3] | If it is a C99 _Bool, it will typically be char-sized, though. - hmm, I found explicitly stated that it should be int |
The same for C++ | |
I guess that other sizes are atypical and not exactly respecting the standard | |
Endo 23-Feb-2012 [2911] | when it is int it could be 64bit or 32bit.. depend on the compiler and the OS. Pekr: So may be the C library returns a 64bit integer: #{0000000001D30000} = #{00000000 - 01D30000}, the left part is 0 (=false) the second part is just a number from stack.. When you get in from R2 it become #{01D30000} = 30605312 |
Geomol 23-Feb-2012 [2912] | Or it's a 16 bit return, and the machine, it's from, is little endian, where World is big endian. Then it's the last 4 zeros in the result, that is the bool. |
Endo 23-Feb-2012 [2913] | That could be too. |
Cyphre 23-Feb-2012 [2914x2] | Lad, In C I tried: #include <stdbool.h> int main (int argc, const char * argv[]) { printf ("bool length %d\n", sizeof(bool)); return 0; } The output was: bool length 1 So it is usually char, at least in GNU C/C++ |
I haven't found any explicit type definition in the C99 though. | |
Andreas 23-Feb-2012 [2916x2] | {"If it is a C99 _Bool, it will typically be char-sized, though." -- hmm, I found explicitly stated that it should be int} Where? |
A slightly better test would be: #include <stdio.h> int main(int argc, char *argv[]) {printf("%ld\n", sizeof(_Bool)); return 0;} And then compile that in C99 mode (i.e. -std=c99 for GCC; but C89/90 compilers will bark on the unknown _Bool keyword anyway). Better, because there exist(ed) a few stdbool.h versions prior to the final C99 standard which used e.g. unsigned integers for bools. Should be gone/fixed by now, but one never knows :) | |
Geomol 23-Feb-2012 [2918] | Under OS X using gcc, I get bool length 1 both with Cyphre and Andreas versions, and also with or without -std=c99 option. |
Cyphre 23-Feb-2012 [2919:last] | Yes, I also used the C99 compiler flag. Andreas version is more correct test ofcourse. |
older | first |