Search code examples
clinuxelfobject-filessymbol-table

C Prototype Function - object file


When compiling a c source file in Linux how a prototype function is treated? Is the symbol stored in the object file (formatted as ELF file) or a signature is stored to make reference to it when linking? For example:

#define MAX 32
typedef struct{
    float[3][3];
}Tensor_t;

float tensor_trace(Tensor_t* t);

Is "tensor_trace" allocated somwhere?


Solution

  • BTW, you need to give the float array a name.

    If you compile the shown source as a C file an empty object file will be the result. No symbol will be stored.

    If you use the shown source as a header file included in another C file which does not call tensor_trace(), the object file will have no symbol stored for it.

    If you use the shown source as a header file included in another C file which does call tensor_trace(), the object file will have a symbol stored for it. At the place where the call is generated a reference to this symbol is placed. The linker will resolve this reference to the function which will have to be defined in another module.

    So to answer your question:

    Is "tensor_trace" allocated somwhere?

    The machine code for tensor_trace() will be "allocated" in the module that defines it. The declaration does not allocate any space.