Understanding sizeof(char) in 32 bit C compilers

后端 未结 8 2326
情歌与酒
情歌与酒 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:48

    It works the same way as using half a piece of paper. You use one part for a char and the other part for something else. The compiler will hide this from you since loading and storing a char into a 32bit processor register depends on the processor.

    Some processors have instructions to load and store only parts of the 32bit others have to use binary operations to extract the value of a char.

    Addressing a char works as it is AFAIR by definition the smallest addressable memory. On a 32bit system pointers to two different ints will be at least 4 address points apart, char addresses will be only 1 apart.

提交回复
热议问题