Public Group

#### Archived

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

# Variable argument lists

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

## 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 on other sites
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 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 on other sites
Wow, thanks for all your help.

1. 1
2. 2
Rutin
24
3. 3
JoeJ
19
4. 4
5. 5
gaxio
13

• 17
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631729
• Total Posts
3001918
×