Re: Array parameter causes undefined behavior?



On Oct 20, 12:22 pm, "Johannes Schaub (litb)" <schaub-johan...@xxxxxx>
wrote:
(This was sent to comp.lang.c++.moderated, but as there is the same
restriction in C, i send it to this one too.) What is the reason that the
following code causes undefined behavior?

// undefined behavior
void f(char const paramN[], ...) {
  va_list ap;
  va_start(ap, paramN);
  va_end(ap);

}

As far as i can see, that's just a parameter with type "char const*". What's
the reason of treating it different? 7.15.1.4/4 in n1256:

"If the parameter parmN is declared with the register storage class, with a
function or array type, or with a type that is not compatible with the type
that results after application of the default argument promotions, the
behavior is undefined."

What about function or arrays? Is there some old implementation that
actually behaved in some strange way?

paramN is not an array. It is a pointer. Also note that "function
type" does not include function pointer type.

REH
.



Relevant Pages

  • Re: how to calculate matrix with out for loop
    ...     end ... I have no clue what you're trying to do here. ... You can tack on 7 zeros if you want (for some reason) to match your ... I'd choose some other name for your array than I. ...
    (comp.soft-sys.matlab)
  • Re: Adjacent arrays in C99
    ... Same result as the first example -- undefined behavior. ... terms of a pointer pointing into, or one past, 'an array object'. ... Standard says that no restrictions apply on what implementations ...
    (comp.std.c)
  • Re: SSCANF
    ... This gives undefined behavior. ... You're trying to modify ... in this context will evalutate to pointers to their ... array of three char). ...
    (comp.lang.c)
  • Re: promotion and narrowing integer conversion
    ... And it's undefined behavior and should ... Otherwise, if the source value fits in the target type, the conversion ...     Otherwise, if either the source or the target is floating-point, ...
    (comp.lang.c)
  • Re: usage of size_t
    ... size_t is the type yielded by the sizeof operator. ... an array definition ... has chosen to define an extension for the undefined behavior. ... for a moment it isn't (ie assume temporarily the declaration is ...
    (comp.lang.c)