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

后端 未结 4 1669
佛祖请我去吃肉
佛祖请我去吃肉 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:53

    As others pointed out, sizeof() can take any valid identifier, but it won't return a valid (an honestly true and valid) result for function names. Furthermore, it definitely may, or may not, result in "demons out of nose" syndrome.

    If you want to profile your program function size, check the linker map, which can be found on the intermediate results directory (the one where things are compiled into .obj/.o or where the resulting image/executable lays). Sometimes there's an option to generate or not this map file... it's compiler/linker dependent.

    If you wanted the size of a pointer to a function, they're all the same size, the size of an addressing word on your cpu.

提交回复
热议问题