Archived

This topic is now archived and is closed to further replies.

Variable argument lists

This topic is 5278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there an alternative to the variable argument list that does provide strict type checking? Also on a totally unrelated note, how exactly does one use those text boxes to paste their code into the forums? Thank you.

Share this post


Link to post
Share on other sites
quote:
Original post by kelaklub
Is there an alternative to the variable argument list that does provide strict type checking? Also on a totally unrelated note, how exactly does one use those text boxes to paste their code into the forums?
Thank you.


Hmm... you could try some way of encoding the type in the struct. A relatively common idiom is something like:


typedef enum {
MyType_Int,
MyType_Double
} MyType_Info;

typedef union {
struct { MyType_Info type; } info;
struct { MyType_Info type; int f; } foo;
struct { MyType_Info type; double b; } bar;
} MyType;

// In some function

switch (myObject->info.type) {
case MyType_Int: { /* Do stuff with myObject->foo */ }
case MyType_Double: { /* Do stuff with myObject->bar */ }
}


Then you just pass in an array of
MyType 
''s and the size of the array.


As for putting the text boxes, I assume you mean what I did above with the code. You just put it in [ source ] [ /source ] tags. To get a "this is code, not text" (like MyType) put it in [ code ] [ /code ] tags.

Share this post


Link to post
Share on other sites