Include header files more than once

#include <stdio.h>
#include <stdio.h>

int main ()
{
   printf ("hello world");
   return 0;
}

when I compile this, the compiler does not give any warnings / errors to turn on stdio.htwice. Why is this so? Are functions now declared and not defined scanf, printfetc.?

Thanks in advance

+3
source share
4 answers

Typically, header files are written like the following example to prevent this problem:

#ifndef MYHEADER
#define MYHEADER

...


#endif

Then, if it is turned on more than once, then the second instance skips the contents.

+11
source

, , , . :

int foo(int, char *);
int foo(int a, char *p);
extern int foo(int x, char y[]);

, , , " " , , .

, ; - . () printf scanf , .

+2

, , #ifndef , undefined.

.

0

, "#ifndef" , (, ).

#ifndef "private", "". , .

, , , , , , , .

, . .

-4

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


All Articles