A
arnuld
I am running into some issue of inclusion of header and I am unable to
understand what is wrong:
fileA.h
#ifndef TEST_HEADERS_A
#define TEST_HEADERS_A
struct myStruct_A
{
int num;
};
void use_print_values(void);
#endif
fileB.h
#ifndef TEST_HEADERS_B
#define TEST_HEADERS_B
#include "fileA.h"
void print_values(struct s1 s);
#endif
fileA.c
#include <stdio.h>
#include "fileA.h"
#include "fileB.h"
void use_print_values(void)
{
struct myStruct_A s;
print_values(s);
}
fileB.c
#include <stdio.h>
#include "fileA.h"
#include "fileB.h"
void print_values(struct myStruct_A s)
{
printf("Num = %d\n", s.num);
}
==================== OUTPUT ======================
[arnuld@dune C]$ gcc -ansi -pedantic -Wall -Wextra -c fileA.c
In file included from fileA.c:3:
fileB.h:6: warning: ‘struct s1’ declared inside parameter list
fileB.h:6: warning: its scope is only this definition or declaration,
which is probably not what you want
fileA.c: In function ‘use_print_values’:
fileA.c:8: error: type of formal parameter 1 is incomplete
[arnuld@dune C]$
[arnuld@dune C]$ gcc -ansi -pedantic -Wall -Wextra -c fileB.c
In file included from fileB.c:3:
fileB.h:6: warning: ‘struct s1’ declared inside parameter list
fileB.h:6: warning: its scope is only this definition or declaration,
which is probably not what you want
fileB.c:6: error: conflicting types for ‘print_values’
fileB.h:6: error: previous declaration of ‘print_values’ was here
[arnuld@dune C]$
understand what is wrong:
fileA.h
#ifndef TEST_HEADERS_A
#define TEST_HEADERS_A
struct myStruct_A
{
int num;
};
void use_print_values(void);
#endif
fileB.h
#ifndef TEST_HEADERS_B
#define TEST_HEADERS_B
#include "fileA.h"
void print_values(struct s1 s);
#endif
fileA.c
#include <stdio.h>
#include "fileA.h"
#include "fileB.h"
void use_print_values(void)
{
struct myStruct_A s;
print_values(s);
}
fileB.c
#include <stdio.h>
#include "fileA.h"
#include "fileB.h"
void print_values(struct myStruct_A s)
{
printf("Num = %d\n", s.num);
}
==================== OUTPUT ======================
[arnuld@dune C]$ gcc -ansi -pedantic -Wall -Wextra -c fileA.c
In file included from fileA.c:3:
fileB.h:6: warning: ‘struct s1’ declared inside parameter list
fileB.h:6: warning: its scope is only this definition or declaration,
which is probably not what you want
fileA.c: In function ‘use_print_values’:
fileA.c:8: error: type of formal parameter 1 is incomplete
[arnuld@dune C]$
[arnuld@dune C]$ gcc -ansi -pedantic -Wall -Wextra -c fileB.c
In file included from fileB.c:3:
fileB.h:6: warning: ‘struct s1’ declared inside parameter list
fileB.h:6: warning: its scope is only this definition or declaration,
which is probably not what you want
fileB.c:6: error: conflicting types for ‘print_values’
fileB.h:6: error: previous declaration of ‘print_values’ was here
[arnuld@dune C]$