Click here to Skip to main content
16,016,562 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: header file not being read (resource.h) Pin
ForNow11-Jan-22 14:06
ForNow11-Jan-22 14:06 
GeneralRe: header file not being read (resource.h) Pin
ForNow11-Jan-22 14:14
ForNow11-Jan-22 14:14 
AnswerRe: header file not being read (resource.h) Pin
Mircea Neacsu11-Jan-22 15:09
Mircea Neacsu11-Jan-22 15:09 
GeneralRe: header file not being read (resource.h) Pin
ForNow11-Jan-22 16:01
ForNow11-Jan-22 16:01 
QuestionMessage Closed Pin
9-Jan-22 7:59
Member 149687719-Jan-22 7:59 
AnswerRe: Implementing variable length parameter - variadic funetion Pin
k50549-Jan-22 8:38
mvek50549-Jan-22 8:38 
GeneralMessage Closed Pin
9-Jan-22 10:31
Member 149687719-Jan-22 10:31 
GeneralRe: Implementing variable length parameter - variadic funetion Pin
k50549-Jan-22 12:19
mvek50549-Jan-22 12:19 
This is the mechanism that printf() uses to pass mixed arguments in, so its definitely doable. printf uses its format string to help unpack the argument list, but there are other ways. You could use a simplified format string like "sddi", showing that the unspecified arguments are a string, two doubles and an int. Another option might be to use an indicator e.g
C
#define ARG_INT 1
#define ARG_LONG 2
#define ARG_DOUBLE 3
#define ARG_CHAR 4
#define ARG_STRING 5
  // ... 
#define ARG_END -1

int var_arg_fn(int arg, ...)
{
    va_ist args;
    va_start(args, arg);
    while(arg != ARG_END) {
        switch(arg) {
           case ARG_INT :
           {
              int i = va_arg(args, int);
              // ...
              break;
           }
           case ARG_DOUBLE :
           {
              double d = va_arg(args, double);
               // ...
              break;
           }
           // ... etc ...
           default:
              // handle error, maybe 
        }
        arg = va_arg(args, int);
    }
}
// and then call it like
var_arg_fn(ARG_INT, 1, ARG_DOUBLE, 3.2, ARG_STRING, strvar, ARG_END); 
I'm sure if you think about it, you can come up with something that suits your needs.
But since you're using C++ now might be the time to venture into the world of variadic fuction templates. Google for that and check out one or more of the tutorials and/or examples. It might be a better fit than trying to wrap things back down to C stdargs.
Update: Here's a video on variadic templates that may help

C++ Weekly - Ep 6 Intro To Variadic Templates - YouTube
Keep Calm and Carry On


modified 9-Jan-22 18:37pm.

GeneralRe: Implementing variable length parameter - variadic funetion Pin
Richard Andrew x649-Jan-22 11:30
professionalRichard Andrew x649-Jan-22 11:30 
GeneralRe: Implementing variable length parameter - variadic funetion Pin
k50549-Jan-22 12:24
mvek50549-Jan-22 12:24 
QuestionMessage Closed Pin
8-Jan-22 6:57
Member 149687718-Jan-22 6:57 
SuggestionRe: Help with Bluetooth -seeking assistance with QT implementation of bluez library . Pin
Richard Deeming9-Jan-22 21:27
mveRichard Deeming9-Jan-22 21:27 
Questionvacancy for google programmer with specification variation. (question) Pin
Dev Lil5-Jan-22 9:38
Dev Lil5-Jan-22 9:38 
AnswerRe: vacancy for google programmer with specification variation. (question) Pin
Dave Kreskowiak5-Jan-22 10:40
mveDave Kreskowiak5-Jan-22 10:40 
AnswerRe: vacancy for google programmer with specification variation. (question) Pin
Gerry Schmitz5-Jan-22 11:56
mveGerry Schmitz5-Jan-22 11:56 
AnswerRe: vacancy for google programmer with specification variation. (question) Pin
Stefan_Lang8-Jan-22 4:00
Stefan_Lang8-Jan-22 4:00 
Questionquestion about CDC:Pie Pin
ForNow5-Jan-22 1:55
ForNow5-Jan-22 1:55 
AnswerRe: question about CDC:Pie Pin
Gerry Schmitz5-Jan-22 5:30
mveGerry Schmitz5-Jan-22 5:30 
GeneralRe: question about CDC:Pie Pin
ForNow5-Jan-22 5:43
ForNow5-Jan-22 5:43 
GeneralRe: question about CDC:Pie Pin
Gerry Schmitz5-Jan-22 7:14
mveGerry Schmitz5-Jan-22 7:14 
GeneralRe: question about CDC:Pie Pin
ForNow5-Jan-22 8:30
ForNow5-Jan-22 8:30 
GeneralRe: question about CDC:Pie Pin
Gerry Schmitz5-Jan-22 12:05
mveGerry Schmitz5-Jan-22 12:05 
GeneralRe: question about CDC:Pie Pin
ForNow5-Jan-22 12:37
ForNow5-Jan-22 12:37 
QuestionSaving a memory DC to a file Pin
ForNow4-Jan-22 4:42
ForNow4-Jan-22 4:42 
AnswerRe: Saving a memory DC to a file Pin
Mircea Neacsu4-Jan-22 5:10
Mircea Neacsu4-Jan-22 5:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.