Why is the size of a function in C always 1 byte?

后端 未结 4 1673
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 00:14

When we check the size of a function using sizeof(), we always get 1 byte. What does this 1 byte signify?

4条回答
  •  孤独总比滥情好
    2020-11-30 00:44

    It's a constraint violation, and your compiler should diagnose it. If it compiles it in spite of that, your program has undefined behaviour [thanks to @Steve Jessop for the clarification of the failure mode, and see @Michael Burr's answer for why some compilers allow this]: From C11, 6.5.3.4./1:

    The sizeof operator shall not be applied to an expression that has function type

提交回复
热议问题