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 CCS Technical Support

Initialize values in struct

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



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

Initialize values in struct
PostPosted: Wed Feb 09, 2005 6:57 am     Reply with quote

Why can't I init values in the struct?

struct DevCSW
{
BYTE Signature[4];
BYTE Tag[4]; BYTE DataResidue[4]; BYTE Status = 0; <---- Error: Expecting a ; or ,

};
_________________
Alex
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 7:28 am     Reply with quote

With that bit of code, you have only informed the compiler that you want a struct that looks like that with a name "DevCSW". If I am not mistaken, this is the "tag". You can use this tag to declare structures of this type later, such as passing to or returning from a function. You have not as yet actually declared a structure in memory because you have not given it an identifier. You can do this by either adding an identifier following the end brace but prior to the semicolon, or on a separate line after the structure declaration:

Code:

struct DevCSW
   {BYTE Signature[4];
   BYTE Tag[4];
   BYTE DataResidue[4];
   BYTE Status;
   } myStruct;

or

struct DevCSW
   {BYTE Signature[4];
   BYTE Tag[4];
   BYTE DataResidue[4];
   BYTE Status;
   };

struct DevCSW myStruct;


To initialize the structure, you must either initialize the members individually or at the time they are defined such as:

Code:

struct DevCSW
   {BYTE Signature[4];
   BYTE Tag[4];
   BYTE DataResidue[4];
   BYTE Status;
   } myStruct = {0,0,0,0,0,0,0,0,0,0,0,0,0};


Hope this helps.
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