Struct forward declaration throws errors

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Struct forward declaration throws errors

767 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Tue Sep 04 20:48:46 MST 2012
Hi,

While programming upon LPCXpresso 4.2, I wanted to use struct's forward declarations, but the compiler throws errors. This is a snippet form my code:

[FONT=Courier New]
[COLOR=Red]typedef _CHRONOMETER_T CHRONOMETER_T;[/COLOR]

struct _CHRONOMETER_T
{
volatile uint32_t msec;
volatile uint32_t sec;
volatile uint32_t min;
int32_t calibration;
};

[COLOR=Red]CHRONOMETER_T cronometro;[/COLOR]

[COLOR=Red]void chrono_Init(CHRONOMETER_T * me, int32_t calibrationValue)[/COLOR]
{
me->msec=0;
me->sec=0;
me->min=0;
me->calibration=calibrationValue;
}
...
[/FONT]

The code in red is where the compiler is founding errors, but I can't see why. No matter where the "typedef..." line is set, the error is still showing up. If I do this the compilation process ends with success:

[FONT=Courier New]struct _CHRONOMETER_T cronometro;
...
void chrono_Init(struct _CHRONOMETER_T * me, int32_t calibrationValue){}
[/FONT]

What Am I missing?

Thank you in advanced :)
0 Kudos
Reply
2 Replies

755 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Sep 05 12:38:12 MST 2012
Hi John,

Yeah, I forgot to write down the "struct" word, What a silly error!!. I did use the second form, but originally I have wanted to use the first one.

Thank you!!
0 Kudos
Reply

755 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by John Sinclair on Tue Sep 04 22:46:36 MST 2012
Hi,

the keyword struct is missing:
typedef struct _CHRONOMETER_T CHRONOMETER_T;
you can also define both in one (struct and type):
typedef struct _CHRONOMETER_T
{
    volatile uint32_t msec;
    volatile uint32_t sec;
    volatile uint32_t min;
    int32_t calibration;
}CHRONOMETER_T;
0 Kudos
Reply