简体   繁体   中英

How do you call this relation between 2 .c files?

I'm a bit confused, I haven't been doing C since years and I'm starting with it right again. One thing I'm not clearly sure is the relation of two files that call each others function, example:

testa.c :

int main (void)
{
    callTheOtherFunction();
    return 0;
}

and the other file

testb.c

callTheOtherFunction(){
//do some stuff
}

now my "makefile" looks like

gcc -o test ./testa.c ./testb.c

What does it mean? Is callTheOtherFunction now part of testa.c, like both files have been merged? Or has it something to do with inheritance ? Is callTheOtherFunction now a global function, or how would you call it?

I need to draw an UML diagram out of it, that's why I need the expression for that case.

The source files are never "merged". What happens is that during compilation phase two object files will be produced - one for each source file and later during linking phase the two object files will be linked(and also linked with some implicit system libraries) producing an executable.

The two files will be compiled to object code by your compiler, then the linker will generate a single executable from the object files. It is, as you say, like the two files have been merged.

callTheOtherFunction will be accessible from anywhere (I suppose you would call that a global function) as you did not mark its definition static .

As a side note, you should probably get a compiler warning from that compilation as you do not have a declaration of callTheOtherFunction in testa.c .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM