Hi all:
I am trying to use data from a structure in different modules ( extern struct), with no success. Here's what I am doing:
main.c:
#include "main.h" struct my_struct new_struct; void main(void) { new_struct.a = 4321; }
file1.c:
#include "main.h" extern my_struct new_struct; void test() { new_struct.a = 1234; }
main.h:
struct my_struct { int a; int b; } The compiler tells me that left side of . requires struct or union.... As I have followed previous threads about this, I see this guidelines are correct. What can be wrong here ? I am using c51 ver 8.12 Thanks in advance Juan
Some observations:
For example, I've pasted the following into Gimpel's online lint gimpel-online.com/.../genPage.py :
struct my_struct { int a; int b; }; extern my_struct new_struct; void test() { new_struct.a = 1234; }
With these results:
FlexeLint for C/C++ (Unix) Vers. 9.00c, Copyright Gimpel Software 1985-2009 --- Module: diy.c (C) _ extern my_struct new_struct; diy.c 10 Info 808: No explicit type given symbol 'my_struct', int assumed diy.c 10 Error 10: Expecting ';' diy.c 10 Error 19: Useless Declaration _ new_struct.a = 1234; diy.c 14 Error 40: Undeclared identifier 'new_struct' diy.c 14 Error 10: Expecting a structure or union diy.c 14 Error 40: Undeclared identifier 'a' diy.c 14 Error 63: Expected an lvalue --- Wrap-up for Module: diy.c Info 753: local struct 'my_struct' (line 4, file diy.c) not referenced diy.c 4 Info 830: Location cited in prior message Info 754: local structure member 'my_struct::a' (line 6, file diy.c) not referenced diy.c 6 Info 830: Location cited in prior message Info 754: local structure member 'my_struct::b' (line 7, file diy.c) not referenced diy.c 7 Info 830: Location cited in prior message --- Global Wrap-up Info 714: Symbol 'test(void)' (line 12, file diy.c) not referenced diy.c 12 Info 830: Location cited in prior message