CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem using a struct from main. in other files.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Problem using a struct from main. in other files.
PostPosted: Fri Aug 08, 2008 3:00 pm     Reply with quote

Hi

Problem using var from main. in other files.

My test project is:
1 main.c and 1 test.c
In main.c

Code:
struct _pos{
 int x;
 int y;
}pos;

int pos_main(){
 return (pos.x+4);
}


in test.c I can use the function "pos_main" but not access the struct?

I know I can put the struct in a .h file and then #include it in main.c and test.c but I dont.

any hints?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Problem using a struct from main. in other files.
PostPosted: Fri Aug 08, 2008 3:03 pm     Reply with quote

Anonymous wrote:
...I know I can put the struct in a .h file and then #include it in main.c and test.c but I dont...


Why don't you? That's what I would do.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Aug 11, 2008 2:18 am     Reply with quote

The other option is to define it as an extern within test.c

Something like

Code:

extern struct _pos{
 int x;
 int y;
} pos;


This then allows you to reference pos within test.c.

I have not tested this with CCS but it is standard C to reference an external variable.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group