| Message |
You can only do compile-time initialization with compile-time constants. The syntax is deceptive as it makes it look like it's doing fancier and potentially dynamic initialization, but really it's just compile-time.
Contrast with this code:
$ cat test.c
typedef unsigned long long int u_int64;
typedef int bool;
#define FALSE 0
#define TRUE 1
extern const struct flag_type area_flags;
extern const struct flag_type sex_flags;
extern const struct flag_type exit_flags;
struct flag_type
{
char *name;
u_int64 bit;
bool settable;
};
struct flag_stat_type
{
const struct flag_type *structure;
bool stat;
};
const struct flag_stat_type flag_stat_table[] =
{
/* { structure stat }, */
{ &area_flags, FALSE },
{ &sex_flags, TRUE },
{ &exit_flags, FALSE },
{ 0, 0 }
};
int main()
{
return 0;
}
In this case, the compiler knows (at compile time, or more accurately at link time) what the address of those structures is, and therefore can (at compile/link time) insert the address into the initialization list.
But it still doesn't compile, although this time for other reasons: the structs are declared as extern but don't actually exist:
$ gcc test.c
/tmp/cc0GQVkE.o:(.rodata+0x0): undefined reference to `area_flags'
/tmp/cc0GQVkE.o:(.rodata+0x8): undefined reference to `sex_flags'
/tmp/cc0GQVkE.o:(.rodata+0x10): undefined reference to `exit_flags'
collect2: ld returned 1 exit status
$
|
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|