C で sizeof を使用して構造体のサイズを取得しましたが、予期しない結果が得られました。
struct sdshdr {
int len;
int free;
char buf[];
};
int main(){
printf("struct len:%d\n",(sizeof(struct sdshdr)));
return 0;
} //struct len:8, with or without buf
私の質問は、なぜbuf
スペースを占有しないのかint
、64 ビット CPU でタイプのサイズがまだ 4 なのかということです。
からの出力は次のgcc -v
とおりです。
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.4.0
Thread model: posix