How to get the length of a function in bytes?

后端 未结 11 1113
醉酒成梦
醉酒成梦 2020-11-28 11:16

I want to know the length of C function (written by me) at runtime. Any method to get it? It seems sizeof doesn\'t work here.

11条回答
  •  心在旅途
    2020-11-28 11:46

    In e.g. Codewarrior, you can place labels around a function, e.g.

    label1:
    void someFunc()
    {
        /* code goes here. */
    }
    label2:
    

    and then calculate the size like (int)(label2-label1), but this is obviously very compiler dependent. Depending on your system and compiler, you may have to hack linker scripts, etc.

提交回复
热议问题