For Programmers: Free Programming Magazines  


Home > Archive > C > March 2004 > nested structure const initialization









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author nested structure const initialization
Bryce Schober

2004-03-30, 9:31 pm

Consider the following two structures:

typedef struct {
int num_data;
int data[];
} part_t;

typedef struct {
int num_parts;
int parts[];
} container_t;

Ideally, I would be able to initialize a container something like
this:

const container_t container = {
2,
{
{ 4, { 1, 2, 3, 4 } },
{ 5, { 1, 2, 3, 4, 5 } },
}
};

My compiler complains about braces around a scalar initializer, but I
can't figure out a way to do this type of initialization in one neat
chunk. I feel like I must be missing something obvious...
Jeremy Yallop

2004-03-30, 9:31 pm

Bryce Schober wrote:
> Consider the following two structures:
>
> typedef struct {
> int num_data;
> int data[];
> } part_t;
>
> typedef struct {
> int num_parts;
> int parts[];


Did you mean to write

part_t parts[];

here?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com