The compiler can find the function without matching the .h file?

I am writing a C university project and stumbled upon compiler behavior that I do not understand.

In this file http://code.google.com/p/openu-bsc-maximveksler/source/browse/trunk/20465/semester/tasks/maman14/alpha/maman14/assembler/phaseOne.c?r=112 I added calling a function called freeAsmInstruction (). This function is defined in a file called lineParser.c, but I have not updated the corresponding lineParser.h header file to include this function declaration.

Why is this code compiling? I would expect gcc to not be able to compile phaseOne.c until the correct lineParser.h is updated with the declaration of freeAsmInstruction ().

I would appreciate an explanation.

Thanks Maxim

+3
source share
3 answers

The GCC compiler accepts a specific function signature by default. To get a warning about this, compile the -Wall flag:

gcc -Wall -c phaseOne.c

this will give you a form warning:

phaseOne.c:2: warning: implicit declaration of function 'your func here'

Unless you have a good reason, you should always compile with the -Wall flag, and possibly with other warning flags.

+3
source

Undefined ; , , , - , . , - , , ( , ); .

. , gcc -Wall -Werror CFLAGS Makefile.

+1

:

a1.c

#include <stdio.h>

int main() {
    // using the external object

    testing();

    return 0;
}

, a2.c

void testing() {
    printf("temp\n");
}

, , :

$ gcc a1.c a2.c -o a1

and he works

Actually, when you compiled your file, did you include another C ( lineParser.c) file at the compilation stage, which will be analyzed along with your file ParseOne.c?

In this case, I understand that it will gccactually analyze all the characters in the linked C files (or obj files) and replace them accordingly in the final file of the object that will be created.

Hope this helps.

-1
source

Source: https://habr.com/ru/post/1736794/


All Articles