public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Array of Structures Initialization
@ 2004-11-15 14:22 Kevin Stedman
  2004-11-15 14:41 ` Eljay Love-Jensen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kevin Stedman @ 2004-11-15 14:22 UTC (permalink / raw)
  To: gcc-help

Hello All,

Can someone give me an idea on how to figure out what
is going on with my initialization of an array of
structures.  This code compiles on Sun using the Sun
One studio CC compiler.  I am porting it to lnux and
have never seen this problem before.  Code examples of
what I am trying to compile are below.  Everything is
in the C header file.  When I compile I do not have
any gcc flags except for -g -c -o.  I get error
messages: "initializer element is not constant" and
"incompatible types in initialization" on every line
of the initialization of the array of structures
below.

#define INTEGER4 4
#define REAL8 8
#define STRING 9

typedef union{
	double RealX8;
	long IntX4;
	char *Str;
} InputValue;

typedef struct _Arguments{
	int keyword;			
	char *prompt_string;		
	char *default_string;		
	int type;			
        InputValue default_value;	
} Arguments;

Arguments SortLightningArgs[]={
	{Title, "NLDN Sort Routine (US
only)",NULL,INTEGER4,NULL},
	{UserDefined,"Minimum propagation
delay",".001",REAL8,NULL},
	{UserDefined,"Maximum propagation
delay","1.0",REAL8,NULL},
	{UserDefined,"Minimum latitude","20.0", REAL8,NULL},
	{UserDefined,"Maximum latitude","50.0", REAL8,NULL},
	{UserDefined,"Minimum longitude","-50.0",
REAL8,NULL},
	{UserDefined,"Maximum longitude","-150.0",
REAL8,NULL},
	{UserDefined,"Input file containing NLDN event
times","lightning.times.251_253", STRING,NULL},
	{UserDefined,"Output file containing list of time
differences and intensities",
                   "HistoTimeDifs.txt", STRING,NULL},
	{NULL,NULL,NULL,NULL,NULL}
};


Thank You for any help,

Kevin


		
__________________________________ 
Do you Yahoo!? 
Check out the new Yahoo! Front Page. 
www.yahoo.com 
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Array of Structures Initialization
  2004-11-15 14:22 Array of Structures Initialization Kevin Stedman
@ 2004-11-15 14:41 ` Eljay Love-Jensen
  2004-11-15 14:42 ` Ramana Radhakrishnan
  2004-11-15 15:06 ` serge fukanchik
  2 siblings, 0 replies; 4+ messages in thread
From: Eljay Love-Jensen @ 2004-11-15 14:41 UTC (permalink / raw)
  To: Kevin Stedman, gcc-help

Hi Kevin,

It looks like you are using NULL to initialize a union.  If I recall 
correctly, you can't do that in C (nor in C++).

Change the Arguments default_value to:
InputValue* default_value;
You'll have to allocate a InputValue structure explicitly.

Or remove InputValue from Arguments and add in:
double default_Double;
long default_Long;
char* default_CharStar;

Yeah, it wastes a few bytes.  But it's just a few bytes, and unless every 
byte is valuable it shouldn't be too egregious overhead.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Array of Structures Initialization
  2004-11-15 14:22 Array of Structures Initialization Kevin Stedman
  2004-11-15 14:41 ` Eljay Love-Jensen
@ 2004-11-15 14:42 ` Ramana Radhakrishnan
  2004-11-15 15:06 ` serge fukanchik
  2 siblings, 0 replies; 4+ messages in thread
From: Ramana Radhakrishnan @ 2004-11-15 14:42 UTC (permalink / raw)
  To: Kevin Stedman; +Cc: gcc-help

Kevin Stedman wrote:
> Hello All,
> 
> Can someone give me an idea on how to figure out what
> is going on with my initialization of an array of
> structures.  This code compiles on Sun using the Sun
> One studio CC compiler.  I am porting it to lnux and
> have never seen this problem before.  Code examples of
> what I am trying to compile are below.  Everything is
> in the C header file.  When I compile I do not have
> any gcc flags except for -g -c -o.  I get error
> messages: "initializer element is not constant" and
> "incompatible types in initialization" on every line
> of the initialization of the array of structures
> below.
> 
> #define INTEGER4 4
> #define REAL8 8
> #define STRING 9
> 
> typedef union{
> 	double RealX8;
> 	long IntX4;
> 	char *Str;
> } InputValue;
> 
> typedef struct _Arguments{
> 	int keyword;			
> 	char *prompt_string;		
> 	char *default_string;		
> 	int type;			
>         InputValue default_value;	
> } Arguments;
> 
> Arguments SortLightningArgs[]={
> 	{Title, "NLDN Sort Routine (US
> only)",NULL,INTEGER4,NULL},
> 	{UserDefined,"Minimum propagation
> delay",".001",REAL8,NULL},
> 	{UserDefined,"Maximum propagation
> delay","1.0",REAL8,NULL},
> 	{UserDefined,"Minimum latitude","20.0", REAL8,NULL},
> 	{UserDefined,"Maximum latitude","50.0", REAL8,NULL},
> 	{UserDefined,"Minimum longitude","-50.0",
> REAL8,NULL},
> 	{UserDefined,"Maximum longitude","-150.0",
> REAL8,NULL},
> 	{UserDefined,"Input file containing NLDN event
> times","lightning.times.251_253", STRING,NULL},
> 	{UserDefined,"Output file containing list of time
> differences and intensities",
>                    "HistoTimeDifs.txt", STRING,NULL},
> 	{NULL,NULL,NULL,NULL,NULL}
> };


I assume you want to define Title, UserDefined  somewhere ? Also you 
might like to include stdio.h for NULL ?

cheers
ramana

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Array of Structures Initialization
  2004-11-15 14:22 Array of Structures Initialization Kevin Stedman
  2004-11-15 14:41 ` Eljay Love-Jensen
  2004-11-15 14:42 ` Ramana Radhakrishnan
@ 2004-11-15 15:06 ` serge fukanchik
  2 siblings, 0 replies; 4+ messages in thread
From: serge fukanchik @ 2004-11-15 15:06 UTC (permalink / raw)
  To: gcc-help

It's possible with the following trick:

Arguments SortLightningArgs[]={
	{Title, "NLDN Sort Routine (US only)",NULL,INTEGER4,         {RealX8: 0}},
	{UserDefined,"Minimum propagation delay",".001",REAL8,       {RealX8: 0}},
	{UserDefined,"Maximum propagation delay","1.0",REAL8,        {RealX8: 0}},
	{UserDefined,"Minimum latitude","20.0", REAL8,               {RealX8: 0}},
	{UserDefined,"Maximum latitude","50.0", REAL8,               {RealX8: 0}},
	{UserDefined,"Minimum longitude","-50.0", REAL8,             {RealX8: 0}},
	{UserDefined,"Maximum longitude","-150.0", REAL8,            {RealX8: 0}},
	{UserDefined,"Input file containing NLDN event times","lightning.times.251_253", STRING,{RealX8: 0}},
	{UserDefined,"Output file containing list of time differences and intensities", "HistoTimeDifs.txt", STRING,{RealX8: 0}},
	{0,NULL,NULL,0,{Str: NULL}}
};

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-15 15:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-15 14:22 Array of Structures Initialization Kevin Stedman
2004-11-15 14:41 ` Eljay Love-Jensen
2004-11-15 14:42 ` Ramana Radhakrishnan
2004-11-15 15:06 ` serge fukanchik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).