Archived

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

kelaklub

Variable argument lists

Recommended Posts

kelaklub    160
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
glassJAw    128
Not too sure what you mean by type checking.

If you want to pass a variable amount of a certain type, just pass a pointer to a vector or list.

Share this post


Link to post
Share on other sites
Way Walker    745
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