Re: stdarg problems
On Jul 1, 6:37 pm, Robert Bauck Hamar <roberth+n...@ifi.uio.no> wrote:
Obnoxious User wrote:
On Sun, 01 Jul 2007 15:50:50 +0000, nariknahom wrote:
f1( 25 > 50,"testing stdarg. ", "it is working", "if it is working.",0 =
);
I believe this should be
f1( 25 > 50,"testing stdarg. ", "it is working", "if it is working.",
static_cast<const char*>(0) );
To make it guaranteed to work. Variable argument functions are
mine fields.
And C++ offers enough other possibilities that they typically
aren't needed.
The reason is that you must use the same type in va_arg as in
the call, and also because the integer 0 is not required to
have the same binary representation as a null pointer.
In practice, I don't know of a single 64 bit machine where they
have the same representation. The integer 0 is almost always a
32 bit quantity on 64 bit machines, where as a char const* is a
64 bit quantity. Depending on how arguments are passed, you may
end up with a very strange looking pointer if you just pass a 0,
without the cast.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34