Reputation: 1297
What Is the difference between how the char datatype is stored or represented in 32bit vs 64bit in C?
Upvotes: 1
Views: 385
Reputation: 96109
One possible difference is that chars might be aligned on 64bit rather than 32bit boundaries.
struct {
char a;
char b;
}
Might take up 2 * 4 bytes on 32bit and 2 * 8 bytes on 64bit.
edit -actually it wouldn't. Any sane complier would repack a struct with only chars on byte boundary. However if you added a 'long c;' in the end anything could happen. That's why a) you have sizeof() and b) you should be careful doing manual pointer stuff in c.
Upvotes: 4
Reputation: 108938
There is no difference.
One char occupies one byte.
One byte has CHAR_BIT bits.
#include <limits.h>
#include <stdio.h>
int main(void) {
printf("a char occupies 1 byte of %d bits.\n", CHAR_BIT);
return 0;
}
Upvotes: 8