In article <11*********************@z14g2000cwz.googlegroups. com>,
<qi*****@gmail.com> wrote:
I have define a struction
typedef struct
{
int Name;
int Year;
}birth;
Now I'd like to define a sequence of A, such as
Birth A = {1,1990}
Birth B = {1,1991}
birth A = {1,1990};
birth B = {1,1991};
:I hope to use #define so that A,B can be used as constant.
:Can I?
No.
What you can do is
#define B90 {1,1990}
#define B91 {1,1991}
birth A = B90;
birth B = B91;
and use B90 or B91 wherever else in the code that you happen to need
to initialize new variables to those values.
But A and B will be writable. You cannot create an unwritable structure
with any particular contents: the closest you can get is, as in the
above, to define textual substituations that happen to expand to the
values you need.
You could also get fancier with functions that return const pointers
to structures. You could probably even have something like
const birth B90(void) { birth B90_temp = {1,1990}; return B90_temp; }
but returning whole structures tends to make old-time programmers
queasy.
--
Watch for our new, improved .signatures -- Wittier! Profounder! and
with less than 2 grams of Trite!