-
January 31st, 2014, 12:52 AM
#1
Why it give warning message, how will it remove
Test1.h
---------------------
#ifndef TEST1_H_
#define TEST1_H_
#include "Test2.h"
typedef struct _Test1{
int a;
int b;
int (*add)(struct _Test1 *test1, struct _Test2 *test2);
}Test1;
Test1 newTest1();
#endif /* TEST1_H_ */
Test1.c
-----------------------------
#include "Test1.h"
static int test1_add(Test1 *test1, Test2 *test2){
return (test1->a + test1->b) + (test2->c + test2->d);
}
Test1 newTest1(){
Test1 test1;
test1.a = 5;
test1.b =6;
test1.add = &test1_add;
return test1;
}
Test2.h
------------------------
#ifndef TEST2_H_
#define TEST2_H_
#include "Test1.h"
typedef struct _Test2{
int c;
int d;
int (*substract)(struct _Test2 *test2, struct _Test1 *test1);
}Test2;
Test2 newtest2();
#endif /* TEST2_H_ */
Test2.c
----------------------------------
#include "Test2.h"
static int test2_substract(Test2 *test2, Test1 *test1){
return (test2->c + test2->d) - (test1->a + test1->b);
}
Test2 newtest2(){
Test2 test2 ;
test2.c = 15;
test2.d = 25;
test2.substract = &test2_substract;
return test2;
}
MakeFile
--------------------------------
all:
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Test1.d" -MT"Test1.d" -o "Test1.o" "Test1.c"
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Test2.d" -MT"Test2.d" -o "Test2.o" "Test2.c"
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "main.c"
warning message:
-------------------------------
make all
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Test1.d" -MT"Test1.d" -o "Test1.o" "Test1.c"
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Test2.d" -MT"Test2.d" -o "Test2.o" "Test2.c"
In file included from Test1.h:12,
from Test1.c:10:
Test2.h:18: warning: ‘struct _Test1.h declared inside parameter list
Test2.h:18: warning: its scope is only this definition or declaration, which is probably not what you want
In file included from Test2.h:12,
from Test2.c:9:
Test1.h:17: warning: ‘struct _Test2.h declared inside parameter list
Test1.h:17: warning: its scope is only this definition or declaration, which is probably not what you want
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "main.c"
gcc -o RountStruct Test1.o Test2.o main.o
In file included from Test1.h:12,
from main.c:9:
Test2.h:18: warning: ‘struct _Test1.h declared inside parameter list
Test2.h:18: warning: its scope is only this definition or declaration, which is probably not what you want
main.c: In function ‘main’:
main.c:21: warning: passing argument 2 of ‘test2.substract’ from incompatible pointer type
#gcc -o RountStruct Test1.o Test2.o main.o
-
January 31st, 2014, 01:48 AM
#2
Re: Why it give warning message, how will it remove
I have answered this elsewhere.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|