Используется среда CoCoox, компилятор GCC (Си)
Что то я запутался в препроцессоре, а точнее в работе с #include. Помогите разобраться. Создал для теста пустой проект. Листинг ниже.
main.h
main.c
PHP код:
|
#include "main.h" #include "func.h"
#ifndef testdef #error testdef not def #endif
int main(void) {
while(1) {
} }
|
func.h
PHP код:
|
#ifndef testdef #error testdef not def #endif
|
func.c
PHP код:
|
#include "func.h"
#ifndef testdef #error testdef not def #endif
|
При компиляции получаю следущее
[cc] Parsing ..\..\..\main.c
[cc] Parsing ..\..\..\func.h
[cc] 0 files are up to date.
[cc] 2 total files to be compiled.
[cc] 1 files to be recompiled from dependency analysis.
[cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Wall -ffunction-sections -g -O0 -c -DSTM32F407VG -DSTM32F4XX -IC:\CooCox\CoIDE\workspace -IC:\CooCox\CoIDE\workspace\testinclude -IC:\CooCox\CoIDE C:\CooCox\CoIDE\workspace\testinclude\main.c C:\CooCox\CoIDE\workspace\testinclude\func.c
[cc] In file included from C:\CooCox\CoIDE\workspace\testinclude\func.c:1:0:
[cc] C:\CooCox\CoIDE\workspace\testinclude\func.h:2:2: error: #error testdef not def
[cc] C:\CooCox\CoIDE\workspace\testinclude\func.c:4:3: error: #error testdef not def
Вопрос в следующем. Почему идентификатор
testdef не доступен хотя бы в файле func.h ведь препроцессор при директиве #include "func.h" вставляет его текст непосредственно в листинг. А 2мя строчками ниже в main.c этот идентификатор доступен. Что я упустил?
Кстати если в main.c заменить #include "func.h" на #include "func.c" то в func.c
testdef оказывается доступной.