Topic: Ellipsis and null pointer constant


Author: v.Abazarov@comAcast.net ("Victor Bazarov")
Date: Sat, 24 Jun 2006 01:41:50 GMT
Raw View
Stephan Bergmann wrote:
> Is my understanding correct that with
>
>   void f(int, ...);
>   f(1, 0);
>   f(2, NULL);
>   f(3, static_cast< int * >(0));
>
> neither the first nor the second call portably pass a null pointer
> value as second argument to f (which f could obtain with va_arg(ap,
> int)), and that instead something like the third form must be used?

I think it is implementation-defined.  Some implementations have the
null pointer represented as "all bits zero".  some implementations
also have 'int' and 'int*' of the same size, so passing an int 0 or
a null int* makes no difference.  Of course, on other implementations
it is important to distinguish those, so in general case, you're right.

> I assume so, as pointer conversion (which null pointer constant to
> null pointer value is, 4.10/1) is not mentioned in 5.2.2/7.
>
> (And I guess that the leeway to allow NULL to be defined as any of 0,
> 0L, etc. is there so that the second form *does* work in practice.  Is
> that right?)

It does work in other cases where the conversion is used.  There is
a proposal in place to add 'nullptr' keyword (document n1488, see
http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1488.pdf), if it
doesn't account for ellipsis (and I couldn't find anything), you should
send your corrections or questions to Herb Sutter and Bjarne Stroustrup.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "kanze" <kanze@gabi-soft.fr>
Date: Mon, 26 Jun 2006 09:31:09 CST
Raw View
Stephan Bergmann wrote:

> Is my understanding correct that with

>    void f(int, ...);
>    f(1, 0);
>    f(2, NULL);
>    f(3, static_cast< int * >(0));

> neither the first nor the second call portably pass a null
> pointer value as second argument to f (which f could obtain
> with va_arg(ap, int)), and that instead something like the
> third form must be used?

I presume you mean something like va_arg(ap, int*)---the first
version (and only the first version) works fine with va_arg( ap,
int ).

If so, you're correct.

> I assume so, as pointer conversion (which null pointer
> constant to null pointer value is, 4.10/1) is not mentioned in
> 5.2.2/7.

> (And I guess that the leeway to allow NULL to be defined as
> any of 0, 0L, etc. is there so that the second form *does*
> work in practice.  Is that right?)

More or less.  So that it might work in practice, on a few more
platforms than if int were required.  It's sort of a sop to
broken code, so that the brokenness won't be so apparent
immediately.

--
James Kanze                                           GABI Software
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: stephan.bergmann@sun.com (Stephan Bergmann)
Date: Fri, 23 Jun 2006 14:52:30 GMT
Raw View
Hi all,

Is my understanding correct that with

   void f(int, ...);
   f(1, 0);
   f(2, NULL);
   f(3, static_cast< int * >(0));

neither the first nor the second call portably pass a null pointer value
as second argument to f (which f could obtain with va_arg(ap, int)), and
that instead something like the third form must be used?

I assume so, as pointer conversion (which null pointer constant to null
pointer value is, 4.10/1) is not mentioned in 5.2.2/7.

(And I guess that the leeway to allow NULL to be defined as any of 0,
0L, etc. is there so that the second form *does* work in practice.  Is
that right?)

-Stephan

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]