Understanding sizeof(char) in 32 bit C compilers

后端 未结 8 2331
情歌与酒
情歌与酒 2020-12-17 19:18

(sizeof) char always returns 1 in 32 bit GCC compiler.

But since the basic block size in 32 bit compiler is 4, How does char occup

8条回答
  •  天命终不由人
    2020-12-17 19:45

    Sizeof returns the value in bytes. You were talking about bits. 32 bit architectures are word aligned and byte referenced. It is irrelevant how the architecture stores a char, but to compiler, you must reference chars 1 byte at a time, even if they use up less than 1 byte.

    This is why sizeof(char) is 1.

    ints are 32 bit, hence sizeof(int)= 4, doubles are 64 bit, hence sizeof(double) = 8, etc.

提交回复
热议问题