0

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?

roger21
  • 45
  • 5

1 Answers1

1

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.

the busybee
  • 10,755
  • 3
  • 13
  • 30
  • It is the same thing with a defined type such as: "typedef int bool" ? – roger21 Sep 26 '19 at 17:32
  • Sure. This type definition is only used in the including translation unit. A type definition as such never uses space in allocated sections, only the variables defined with this type. – the busybee Sep 26 '19 at 20:07