C
CptDondo
I am missing something about structure declarations....
I am trying to get the size of a structure member using sizeof.
my xml.h file (beware of line wrap):
struct fieldSchedule_t {
uint8_t action;
uint16_t fromBearing, toBearing;
};
my plc.h file:
#define PLC_FIELD_ACTION (PLC_BASE)
#define PLC_FIELD_TOBRG (PLC_BASE +
SCHEDLINES*sizeof(fieldSchedule_t.action)/PLC_UNIT)
#define PLC_FIELD_FROMBRG (PLC_FIELD_TOBRG +
SCHEDLINES*sizeof(fieldSchedule_t.toBearing)/PLC_UNIT)
my .c file:
#include "xml.h"
#include "plc.h"
main() {
printf("%s %d\n%s %d\n%s %d\n",
"PLC_FIELD_ACTION", PLC_FIELD_ACTION,
"PLC_FIELD_TOBRG", PLC_FIELD_TOBRG,
"PLC_FIELD_FROMBRG", PLC_FIELD_FROMBRG);
}
The way I understand this, I should be able to get the size of the
member action from the "structure tag" in the declaration.
Alas it isn't so:
[i386]yan@craywb:/home/local/panel/src/xml2plc$ gcc test.c
test.c: In function `main':
test.c:10: error: `fieldSchedule_t' undeclared (first use in this function)
test.c:10: error: (Each undeclared identifier is reported only once
test.c:10: error: for each function it appears in.)
Is there some way to get the size of a structure member without actually
allocating space for that structure?
--Yan
I am trying to get the size of a structure member using sizeof.
my xml.h file (beware of line wrap):
struct fieldSchedule_t {
uint8_t action;
uint16_t fromBearing, toBearing;
};
my plc.h file:
#define PLC_FIELD_ACTION (PLC_BASE)
#define PLC_FIELD_TOBRG (PLC_BASE +
SCHEDLINES*sizeof(fieldSchedule_t.action)/PLC_UNIT)
#define PLC_FIELD_FROMBRG (PLC_FIELD_TOBRG +
SCHEDLINES*sizeof(fieldSchedule_t.toBearing)/PLC_UNIT)
my .c file:
#include "xml.h"
#include "plc.h"
main() {
printf("%s %d\n%s %d\n%s %d\n",
"PLC_FIELD_ACTION", PLC_FIELD_ACTION,
"PLC_FIELD_TOBRG", PLC_FIELD_TOBRG,
"PLC_FIELD_FROMBRG", PLC_FIELD_FROMBRG);
}
The way I understand this, I should be able to get the size of the
member action from the "structure tag" in the declaration.
Alas it isn't so:
[i386]yan@craywb:/home/local/panel/src/xml2plc$ gcc test.c
test.c: In function `main':
test.c:10: error: `fieldSchedule_t' undeclared (first use in this function)
test.c:10: error: (Each undeclared identifier is reported only once
test.c:10: error: for each function it appears in.)
Is there some way to get the size of a structure member without actually
allocating space for that structure?
--Yan