IPB

Welcome Guest ( Log In | Register )

> Structure Assignment
Jacob Christ
post Dec 23 2007, 05:22 AM
Post #1


Regular
*

Group: EstablishedMember
Posts: 65
Joined: 13-October 07
From: Rancho Cucamonga, CA
Member No.: 3,843



Whah, this doesn't work!

CODE
typedef struct {
    char foo[11];
    bar_enum bar;
} baz_list;

baz_list baz[] = { "0123456789", quux,
                   "0123456789", quuux,
                   "0123456789", quuuux
                 };


I can create a two dimensional array of strings and initialize them or a array of enums and initialize them but not an array of structs, and that sucks!!! (rhyme intended)

Any suggestions???

Jacob
BoostC 6.81

This post has been edited by Jacob Christ: Dec 23 2007, 05:23 AM
update Picpack 3.0 Released
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
twomers
post Dec 27 2007, 10:04 PM
Post #2


Regular
*

Group: EstablishedMember
Posts: 42
Joined: 28-November 07
From: Ireland
Member No.: 3,919



A more premitive question to ask would be why:

CODE
struct thing {
  char ch_1;
  char ch_2;
};

struct thing thingy = {2,2};


doesn't work.

I can't find the thread I'm thinking of but I believe you're going to have to assign the values yourself. I'd say use an inline function or something to make it look neater:

CODE
struct thing {
  char ch_1;
  char ch_2;
};

inline void set_thing( struct thing &i_thing,
                       unsigned char ch_1,
                       unsigned char ch_2 ) {
  i_thing.ch_1 = ch_1;
  i_thing.ch_2 = ch_2;
}

void main( void ){
  struct thing i_thing[3];
  set_thing( i_thing[0], 2, 3 );
  set_thing( i_thing[1], 5, 3 );
  set_thing( i_thing[2], 1, 9 );

// Or if you wish
//  i_thing[0].ch_1 = 2; i_thing[0].ch_2 = 3;  
//  i_thing[1].ch_1 = 5; i_thing[1].ch_2 = 3;  
//  i_thing[2].ch_1 = 1; i_thing[2].ch_2 = 9;
}


Found the thread - http://forum.sourceboost.com/index.php?showtopic=3404

This post has been edited by twomers: Dec 27 2007, 10:10 PM
Go to the top of the page
 
+Quote Post
Jacob Christ
post Dec 30 2007, 12:09 AM
Post #3


Regular
*

Group: EstablishedMember
Posts: 65
Joined: 13-October 07
From: Rancho Cucamonga, CA
Member No.: 3,843



This worked swell, thanks... Added a couple hundred bytes over head over just using arrays, but the re-usability almost (but not quite) made up for the loss.

I can't wait to see this one fixed...

Jacob
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 3rd September 2010 - 02:48 PM