VLA normally refers to variable length arrays. You don't have any of
those in this program. I suspect you mean variable arguments. No such
promotion should occur.

As far as the C standard is concerned, the type of &p[0] is char(*)
[2]. Why gcc described it as char(*)[1u] is something you'll have to
take up with gcc. It's definitely version dependent. I have access to
gcc versions 3.2.3 and 3.3, both of which simply say:

Whoops, I meant "variadic arguments".
> As far as the C standard is concerned, the type of &p[0] is char(*)
> [2]. Why gcc described it as char(*)[1u] is something you'll have to
> take up with gcc. It's definitely version dependent. I have access to
> gcc versions 3.2.3 and 3.3, both of which simply say:
>
> warning: int format, pointer arg (arg 2)

<snip>
>> As far as the C standard is concerned, the type of &p[0] is char(*)
>> [2]. Why gcc described it as char(*)[1u] is something you'll have to
>> take up with gcc. It's definitely version dependent. I have access to
>> gcc versions 3.2.3 and 3.3, both of which simply say:
>>
>> warning: int format, pointer arg (arg 2)
>
> Thanks.

I suspect it was a bug that has been fixed. I get a far more useful warning:
markg@brenda:~$ gcc -ansi -pedantic -Wall -Wextra -g3 t.c
t.c: In function ‘main’:
t.c:7: warning: format ‘%d’ expects type ‘int’, but argument 2 has type
‘char (*)[2]’
markg@brenda:~$
--
Flash Gordon
If spamming me sent it to
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/

The & operator always results in a value of type pointer to something.
A pointer value is never the appropriate type of argument for %d. And
undefined behavior does break conformance.
>
> return 0;
>}
>
>I'm curious, what is gcc talking about?
>Why is &p[0] a char (*)[1u]?

p is an array of 3 array of 2 char.

p[0] is the first array of 2 char in the above object.

&p[0] is the address of p[0] with type pointer to array of 2 char. The
syntax for this type is char (*)[2].

The standard does not impose any quality requirements on the text of
diagnostics and this diagnostic is not even a required one. So what
you have is a useful message that happens to suffer from a slight
inaccuracy in terminology.
>
>My first guess was that char (*)[N] pointers get promoted to char (*)
>[1] pointers in VLA arguments. (it doesn't make much sense to me
>though)
>
>Can anyone explain (don't answer with a yes; actually do so gcc's
>behavior here?

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!