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

general C question

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



Joined: 11 Apr 2005
Posts: 5

View user's profile Send private message Visit poster's website

general C question
PostPosted: Mon Dec 26, 2005 1:40 pm     Reply with quote

hi all,

I've got a genearal C question here (bit of a noob question)

Here are 2 snippets of code where I am defining a structure and then creating an array of the said structure.

Numero Uno:

Code:
typedef struct
//hold variables used for controlling each individual LED in this structure
{
   short fadeDirection;      //indicate if LED fading up or down
   int fadeSpeed;            //speed of LED fading
   int fadeSpeedCount;         //counter used for each individual LED in BREATH mode
   int pwmDuty;            //length of the duty (on time of an LED)
   int ledMask;            //bits of PORTA or B that needed to be masked out to turn on the
                        //particular LED
}LED_PARAMS;

//populate array used to control all LEDs with initial states of all of the vars
LED_PARAMS LEDcontrol[NUM_LEDS]=
{
   {UP, 200, 0, 0, 0b00000001},
   {UP, 19, 0, 0, 0b00000010},



Numero Dose:

Code:
struct
//hold variables used for controlling each individual LED in this structure
{
   short fadeDirection;      //indicate if LED fading up or down
   int fadeSpeed;            //speed of LED fading
   int fadeSpeedCount;         //counter used for each individual LED in BREATH mode
   int pwmDuty;            //length of the duty (on time of an LED)
   int ledMask;            //bits of PORTA or B that needed to be masked out to turn on the
                        //particular LED
}LED_PARAMS;

//populate array used to control all LEDs with initial states of all of the vars
LED_PARAMS LEDcontrol[NUM_LEDS]=
{
   {UP, 200, 0, 0, 0b00000001},
   {UP, 19, 0, 0, 0b00000010},






As soon as I take typedef out the compiler spits out the following error:

Code:


*** Error 48 "C:\cygwin\home\d\pic_dir\fade_code\fade_code.c" Line 52(12,22): Expecting a (
*** Error 43 "C:\cygwin\home\d\pic_dir\fade_code\fade_code.c" Line 52(22,23): Expecting a declaration


The line num reffers to the begining of array declaration.

From what I understand, not using typedef is a newer way of dealing with structure declaration, but most compilers deal with it well. Furthermore, I have seen snippets on the forum with just struct.

I am just trying to understand more about use of structures and what stupid thing did I do to deserve that errror Smile


THnX in advance for any help


d
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 26, 2005 3:01 pm     Reply with quote

http://www.ecf.utoronto.ca/apsc/courses/ece242f/2004spring/notes-242/notes-general-2.html#struct

http://www.cppworld.com/tutorials/?tutorial=structures
Dima49



Joined: 11 Apr 2005
Posts: 5

View user's profile Send private message Visit poster's website

thnx
PostPosted: Tue Dec 27, 2005 10:45 am     Reply with quote

Thnx PCM!

read the examples makes soooo much more sense now.

d
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