No parameter check in GCC

I wrote a C program that consists of three files in one directory

main.c

#include<stdio.h>
#include "test.h"

int main()
{
        int b=0;
        b = test_add(3,2);
        printf("Added: b=%d\n\n",b);
        return 0;
}

test.h

int test_add(int a, int b);

test.c

int test_add(int a, int b, int c)
{
        return a+b+c;
}

I compile the program using the following command:

$gcc -Wall -Wextra main.c test.c

It compiles successfully. I see that there is a discrepancy in the number of arguments of the calling function and its actual definition. The compiler does not give any warnings / errors for such a problem. How to report this type of error to the compiler?

+4
source share
1 answer

This shows one of the oddities of standard C. It allows objects, such as functions, to be undefined.

The actual mistake is that you are not

#include "test.h"

in the file test.c.

, . , .

, b. , - ;)

include, .

, , -Wall -Wextra -pedantic.

+4

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


All Articles