Я только начинаю с модульного программирования на C. Я думаю, что я делаю что-то неправильно с включениями, потому что я получаю много ошибок conflicting types for 'functionName'
и previous declaration of 'functionName' was here
. Я поместил защитники включения на место.Открытый учебник, объясняющий модульное программирование в C?
Знаете ли вы четкое руководство, объясняющее модульное программирование на C, особенно, как работают включения?
Update: Я пытался изолировать мою проблему. Вот, пожалуйста, какой-то код.
Обновление 2: обновленный код приведен ниже. Ошибки также были обновлены.
/*
* main.c
*/
#include <stdio.h>
#include "aStruct.h"
int main() {
aStruct asTest = createStruct();
return 0;
}
/*
* aStruct.h
*/
#ifndef ASTRUCT_H_
#define ASTRUCT_H_
struct aStruct {
int value1;
int value2;
struct smallerStruct ssTest;
};
typedef struct aStruct aStruct;
aStruct createStruct();
#endif /* ASTRUCT_H_ */
/*
* smallerStruct.h
*/
#ifndef SMALLERSTRUCT_H_
#define SMALLERSTRUCT_H_
struct smallerStruct {
int value3;
};
typedef struct smallerStruct smallerStruct;
smallerStruct createSmallerStruct();
#endif /* SMALLERSTRUCT_H_ */
/*
* aStruct.c
*/
#include <stdio.h>
#include "smallerStruct.h"
#include "aStruct.h"
aStruct createStruct() {
aStruct asOutput;
printf("This makes sure that this code depends on stdio.h, just to make sure I know where the inclusion directive should go (main.c or aStruct.c).\n");
asOutput.value1 = 5;
asOutput.value2 = 5;
asOutput.ssTest = createSmallerStruct();
return asOutput;
}
/*
* smallerStruct.c
*/
#include <stdio.h>
#include "smallerStruct.h"
smallerStruct createSmallerStruct() {
smallerStruct ssOutput;
ssOutput.value3 = 41;
return ssOutput;
}
Это порождает следующие сообщения об ошибках:
At aStruct.h:10
- field 'ssTest' has incomplete type
At main.c:8
- unused variable `asTest' (this one makes sense)
Не могли бы вы разместить образец кода, который дает вам проблемы? – FrustratedWithFormsDesigner
Я добавил образец в соответствии с запросом. – Pieter
Вам нужно # включить "lessStruct.h" в astruct.h – 2010-02-20 10:54:24