Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16500

Re: va_args Conformance

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: va_args Conformance
Date 2012-01-31 11:27 -0500
Organization A noiseless patient Spider
Message-ID <4F281677.3090906@verizon.net> (permalink)
References <jg8ssi$5ea$1@dont-email.me> <0.974e5b6a5e777ba20127.20120131145047GMT.8739awq62g.fsf@bsb.me.uk>

Show all headers | View raw


On 01/31/2012 09:50 AM, Ben Bacarisse wrote:
> Shao Miller <sha0.miller@gmail.com> writes:
> 
>> If the following program strictly conforming?
>>
>>   #include <stddef.h>
>>   #include <stdarg.h>
>>
>>   static void test(int, ...);
>>
>>   int main(void) {
>>       test(0, 42);
>>
>>       return 0;
>>     }
>>
>>   static void test(int x, ...) {
>>       typedef unsigned char one_char[1];
>>       /* Valid declaration on the next line */
>>       one_char * unused;
>>       va_list varargs;
>>       unsigned char * byte;
>>
>>       va_start(varargs, x);
>>       if (x)
>>           byte = va_arg(varargs, one_char);
>>       va_end(varargs);
>>
>>       return;
>>     }
> 
> It looks fine to me.  Does some implementation reject it?

The second argument of his call to test() has a type of int. He calls
va_arg() with a type of one_char, which is a typedef for unsigned char.
"if type is not compatible with the type of the actual next argument (as
promoted according to the default argument promotions), the behavior is
undefined ..." (7.15.1.1p2). The promoted type of "int" is "int".
"unsigned char" is not compatible with "int". That clause has some
exceptions, but none of them are applicable.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

va_args Conformance Shao Miller <sha0.miller@gmail.com> - 2012-01-31 09:12 -0500
  Re: va_args Conformance Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-31 14:50 +0000
    Re: va_args Conformance Shao Miller <sha0.miller@gmail.com> - 2012-01-31 10:11 -0500
      Re: va_args Conformance Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-31 17:19 +0000
        Re: va_args Conformance Shao Miller <sha0.miller@gmail.com> - 2012-01-31 12:31 -0500
          Re: va_args Conformance Shao Miller <sha0.miller@gmail.com> - 2012-01-31 12:34 -0500
            Re: va_args Conformance Shao Miller <sha0.miller@gmail.com> - 2012-01-31 12:40 -0500
          Re: va_args Conformance Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-31 17:52 +0000
    Re: va_args Conformance James Kuyper <jameskuyper@verizon.net> - 2012-01-31 11:27 -0500
      Re: va_args Conformance Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-31 16:53 +0000
        Re: va_args Conformance Shao Miller <sha0.miller@gmail.com> - 2012-01-31 12:09 -0500
        Re: va_args Conformance James Kuyper <jameskuyper@verizon.net> - 2012-01-31 12:15 -0500
  Re: va_args Conformance Harald van Dijk <haraldvdijk@gmail.com> - 2012-01-31 09:46 -0800
    Re: va_args Conformance Shao Miller <sha0.miller@gmail.com> - 2012-01-31 13:45 -0500
      Re: va_args Conformance Harald van Dijk <haraldvdijk@gmail.com> - 2012-01-31 11:28 -0800
      Re: va_args Conformance Harald van Dijk <haraldvdijk@gmail.com> - 2012-01-31 11:33 -0800

csiph-web