A
aekalman
Hi all.
I'm revising part of a large body of code that runs on a variety of
very different targets, and one of the things I'd like to do is move
away from certain "#define'd types" in favor of typedefs. This, mainly
because occasionally a user forgets that these are pointer "types",
and declares one or more variable on the same line, leading to errors.
E.g. right now I have this, which works fine, with the caveat that
only a single variable should be declared per line (because it's a
pointer variable):
typedef struct ecb OStypeEcb;
#define OStypeEcbP OStypeEcb OSLOC_ECB *
used thusly:
OStypeEcbP myEcbP;
and not
OStypeEcbP myEcbP, yourEcbP; // bad!
What is OSLOC_ECB, you ask? Well, it's a bank qualifier for certain
targets (e.g. Microchip PIC16's, where OSLOC_ECB might be nothing,
bank1, bank2 or bank3). The user can
#define OSLOC_ECB
or
#define OSLOC_ECB bank1
etc. to indicate where the objects (the ecb's) being pointed to are
located. So far, so good.
Naturally, I would prefer to have this:
typedef struct ecb OStypeEcb;
typedef OStypeEcb OSLOC_ECB * OStypeEcbP;
But it fails to compile, and I don't really understand why. OSLOC_ECB
is defined long before the typedef is processed by the compiler, yet
preprocessor output (CodeWarrior, in this case) of that line (for
OSLOC_ECB defined to be blank/nothing) reveals
typedef OStypeEcb OSLOC_ECB * OStypeEcbP;
instead of
typedef OStypeEcb * OStypeEcbP;
which is what I would have expected.
Can someone explain to me why defined symbols are not converted inside
the typedef, and if there's a way around this?
Thanks,
--Andrew
aek at pumpkininc dot com
I'm revising part of a large body of code that runs on a variety of
very different targets, and one of the things I'd like to do is move
away from certain "#define'd types" in favor of typedefs. This, mainly
because occasionally a user forgets that these are pointer "types",
and declares one or more variable on the same line, leading to errors.
E.g. right now I have this, which works fine, with the caveat that
only a single variable should be declared per line (because it's a
pointer variable):
typedef struct ecb OStypeEcb;
#define OStypeEcbP OStypeEcb OSLOC_ECB *
used thusly:
OStypeEcbP myEcbP;
and not
OStypeEcbP myEcbP, yourEcbP; // bad!
What is OSLOC_ECB, you ask? Well, it's a bank qualifier for certain
targets (e.g. Microchip PIC16's, where OSLOC_ECB might be nothing,
bank1, bank2 or bank3). The user can
#define OSLOC_ECB
or
#define OSLOC_ECB bank1
etc. to indicate where the objects (the ecb's) being pointed to are
located. So far, so good.
Naturally, I would prefer to have this:
typedef struct ecb OStypeEcb;
typedef OStypeEcb OSLOC_ECB * OStypeEcbP;
But it fails to compile, and I don't really understand why. OSLOC_ECB
is defined long before the typedef is processed by the compiler, yet
preprocessor output (CodeWarrior, in this case) of that line (for
OSLOC_ECB defined to be blank/nothing) reveals
typedef OStypeEcb OSLOC_ECB * OStypeEcbP;
instead of
typedef OStypeEcb * OStypeEcbP;
which is what I would have expected.
Can someone explain to me why defined symbols are not converted inside
the typedef, and if there's a way around this?
Thanks,
--Andrew
aek at pumpkininc dot com