Header Depth Limit

I was wondering, if you include header files, can the depth of the included files increase unlimitedly? Can you specify a limit at compile time?

Example:

main.c:

#include "A.h"
const int xyz = CONST_VALUE;

hijras:

#include "B.h"

Bh:

#include "C.h"

...

...

...

Zh:

#define CONST_VALUE ( 12345 )

Am I right? Is it possible to include header files endlessly?

+6
source share
1 answer

There is a limit that is different from the compiler.

From section 6.10.2 of standard [C]) ( http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf ):

6 A #include , - #include , (. 5.2.4.1).

5.2.4.1:

, :

...

  • 15 #

, , 15 , , , .

, , , .

, :

main.h:

#include "main.h"

extern int x;

main.c:

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

int x = 2;

int main()
{
    printf("x=%d\n",x);
    return 0;
}

gcc :

error: #include

(gcc 4.8.5) 200 , . . gcc, 11.2.

MSVC 10 (. ). , ( ), MSVC .

+4

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


All Articles