stange va_start() behavior
-
hi everybody, i've got a strange error while trying to use va_start() macro. i wrote the following :
va_list ap;
// the following line is failing...
va_start(ap, 0); /* also tried with argument 2 set at 1. */and the compiler gave me an error C2101: '&' on constant when i looked at the MSDN, the example is that one :
int average( int first, ... )
{
va_list marker;
va_start( marker, first ); /* Initialize variable arguments. */
//...
}it seems to be similar with my code, so i don't understand where i fail... can anyone help please ?
TOXCCT >>> GEII power
-
hi everybody, i've got a strange error while trying to use va_start() macro. i wrote the following :
va_list ap;
// the following line is failing...
va_start(ap, 0); /* also tried with argument 2 set at 1. */and the compiler gave me an error C2101: '&' on constant when i looked at the MSDN, the example is that one :
int average( int first, ... )
{
va_list marker;
va_start( marker, first ); /* Initialize variable arguments. */
//...
}it seems to be similar with my code, so i don't understand where i fail... can anyone help please ?
TOXCCT >>> GEII power
-
The second argument must be the name of an argument in your function. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
but where is the difference ??? if the argument is an integer, its value will be passed... no ?
va_start()
need a reference ? does it need a reference to the first argument of the list ?
TOXCCT >>> GEII power
The difference is the fact that va_start() is a *macro*. The word "first" is literally passed to it, and it is then used. va_start() uses it's second argument by doing &MySecondArg, this is why you get the "& on constant" error (0 in your case). This is because va_start() needs to know where from the stack to read next. Since the second argument you pass to it is one of your function's arguments, taking it's address returns a place on the stack. From there, va_arg() keeps moving. The va_list is simply a pointer to the next place, and this is what gets updated every time you use va_arg(). -- Calius
-
The difference is the fact that va_start() is a *macro*. The word "first" is literally passed to it, and it is then used. va_start() uses it's second argument by doing &MySecondArg, this is why you get the "& on constant" error (0 in your case). This is because va_start() needs to know where from the stack to read next. Since the second argument you pass to it is one of your function's arguments, taking it's address returns a place on the stack. From there, va_arg() keeps moving. The va_list is simply a pointer to the next place, and this is what gets updated every time you use va_arg(). -- Calius
ok, well i can now say that, you are right for some points, but some other are wrong. first (for precision), i've already said in my first post that
va_start()
was a macro ; knowing whatever it means. in fact,va_start()
get a reference to the argument preceding the first of the optional parameter... (so, you're right on this). i so now understand the compiler error (C2101). butva_list
is not a pointer to the next place as you say. it points only one argument (the current), and at the next call ofva_arg()
, this one will increment the pointer to the next argument in the list. that's why va_start() argument must be the preceding... anyway, thanks, i apreciate your answer. i'm now ok with that point... :-D
TOXCCT >>> GEII power
-
ok, well i can now say that, you are right for some points, but some other are wrong. first (for precision), i've already said in my first post that
va_start()
was a macro ; knowing whatever it means. in fact,va_start()
get a reference to the argument preceding the first of the optional parameter... (so, you're right on this). i so now understand the compiler error (C2101). butva_list
is not a pointer to the next place as you say. it points only one argument (the current), and at the next call ofva_arg()
, this one will increment the pointer to the next argument in the list. that's why va_start() argument must be the preceding... anyway, thanks, i apreciate your answer. i'm now ok with that point... :-D
TOXCCT >>> GEII power
-
#define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) ) #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
Ill let you meditate on this Papa while (TRUE) Papa.WillLove ( Bebe ) ;