#14227 - poslundc - Sat Jan 03, 2004 12:06 am
Okay, say I have a struct, I can use typecasting to populate its contents when declaring a variable. eg:
You can even do this with structs-within-structs, arrays of structs, etc.
Some of my structs are getting extremely bulky and complicated, however, and this method is becoming more unwieldy. In one case a struct with about 10 members includes another struct as a member, and that struct has another 15 members or so.
I don't want to have to populate both structs in a single line of code, but it doesn't seem like I can do only a partial declaration (ie. omit some of the members), unless I want to assign each member individually with its own assignment statement (which would just be a royal pain of the opposite kind).
Anyone know of an effective way of dealing with structs when they start to get like this? (Replacing the struct-within-struct with a pointer is not an option in this case.) Or is there some C syntax that can deal with this that I am unaware of?
Thanks,
Dan.
Code: |
typedef struct Rect
{ int x, y, w, h; } Rect; Rect r = (Rect) {10, 15, 32, 32}; |
You can even do this with structs-within-structs, arrays of structs, etc.
Some of my structs are getting extremely bulky and complicated, however, and this method is becoming more unwieldy. In one case a struct with about 10 members includes another struct as a member, and that struct has another 15 members or so.
I don't want to have to populate both structs in a single line of code, but it doesn't seem like I can do only a partial declaration (ie. omit some of the members), unless I want to assign each member individually with its own assignment statement (which would just be a royal pain of the opposite kind).
Anyone know of an effective way of dealing with structs when they start to get like this? (Replacing the struct-within-struct with a pointer is not an option in this case.) Or is there some C syntax that can deal with this that I am unaware of?
Thanks,
Dan.