How can I print the result of sizeof() at compile time in C?

后端 未结 12 1353
星月不相逢
星月不相逢 2020-11-29 20:47

How can I print the result of sizeof() at compile time in C?

For now I am using a static assert (home brewed based on other web resources) to compare the sizeof() re

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 21:28

    Quick and simple solution that worked for me (GCC):

    (char[sizeof(long long)])"bla";
    

    This results in an error message that reveals the size of long long:

    ISO C++ forbids casting to an array type 'char [8]'
    

提交回复
热议问题