Topic: varargs and bool


Author: mikes@forte.com (Mike Schilling)
Date: 1998/01/07
Raw View
Integral types like "short" and "char" are promoted to "int" when
used in a varargs context.  Is "bool" promoted also, and if so, to what?
That is, in

void extract(char type, ...)
{
    va_list ap;

    va_start(ap, type);

 short s;
 char c;
 bool b;

 switch (type)
 {
  's':
  s = (short)(va_arg(ap, int));
  break;

  'c':
  c = (char)(va_arg(ap, int));
  break;

  'b':
  b = (bool)(va_arg(ap, TYPE));
  break;
 }
}

What is the correct value for TYPE?

Thanks,
Mike
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: stephen.clamage@Sun.COM (Steve Clamage)
Date: 1998/01/07
Raw View
On 07 Jan 98 03:25:59 GMT, mikes@forte.com (Mike Schilling) wrote:

>Integral types like "short" and "char" are promoted to "int" when
>used in a varargs context.  Is "bool" promoted also, and if so, to what?

One of the standard integral promotions is bool to int. So, just like
short and char, bool gets promoted to int when used in a varargs
context. Boolean "true" is converted to 1 and "false" is converted to
0.

---
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]