Dima49
Joined: 11 Apr 2005 Posts: 5
|
general C question |
Posted: Mon Dec 26, 2005 1:40 pm |
|
|
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
THnX in advance for any help
d |
|