Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Variably modified arrays

Reply
Thread Tools

Re: Variably modified arrays

 
 
James Kuyper
Guest
Posts: n/a
 
      01-24-2013
On 01/24/2013 11:16 AM, Russell Shaw wrote:
> Hi,
> In gcc-4.7 C99, this is accepted in a block scope:
>
> int n;
>
> struct tag {
> int (*y)[n]; // invalid: y not ordinary identifier
> int z[n]; // invalid: z not ordinary identifier
> };


Our machine has 4.1.2 on it, and I confirm that it does accept this code.

> from 6.7.5.2 p10 example 4 WG14/N1336.
>
> 6.7.2.1 p8
> "A member of a structure or union may have any object type other than a variably
> modified type.(10"
>
> Footnote 108:
> "A structure or union cannot contain a member with a variably modified type
> because member names are not ordinary identifiers as defined in 6.2.3."


In the current standard, those are 6.7.2.1p9 and Footnote 124.

The rule that is violated, because member names are not ordinary
identifiers, is 6.7.6.2p2: "If an identifier is declared as having a
variably modified type, it shall be an ordinary identifier ...".

Since 6.7.6.2 is a Constraints section, a conforming implementation is
required to issue at least one diagnostic message. If, like me, you
didn't get any such message with -Wall and -pedantic, I believe this
constitutes a defect in gcc (or at least, these two versions of it).
 
Reply With Quote
 
 
 
 
Shao Miller
Guest
Posts: n/a
 
      01-24-2013
On 1/24/2013 11:41, James Kuyper wrote:
> On 01/24/2013 11:16 AM, Russell Shaw wrote:
>> Hi,
>> In gcc-4.7 C99, this is accepted in a block scope:
>>
>> int n;
>>
>> struct tag {
>> int (*y)[n]; // invalid: y not ordinary identifier
>> int z[n]; // invalid: z not ordinary identifier
>> };

>
> Our machine has 4.1.2 on it, and I confirm that it does accept this code.
>
>> from 6.7.5.2 p10 example 4 WG14/N1336.
>>
>> 6.7.2.1 p8
>> "A member of a structure or union may have any object type other than a variably
>> modified type.(10"
>>
>> Footnote 108:
>> "A structure or union cannot contain a member with a variably modified type
>> because member names are not ordinary identifiers as defined in 6.2.3."

>
> In the current standard, those are 6.7.2.1p9 and Footnote 124.
>
> The rule that is violated, because member names are not ordinary
> identifiers, is 6.7.6.2p2: "If an identifier is declared as having a
> variably modified type, it shall be an ordinary identifier ...".
>
> Since 6.7.6.2 is a Constraints section, a conforming implementation is
> required to issue at least one diagnostic message. If, like me, you
> didn't get any such message with -Wall and -pedantic, I believe this
> constitutes a defect in gcc (or at least, these two versions of it).
>


int main(int argc, char ** argv) {
struct tag {
int (* y)[argc];
int z[argc];
};
(void) argc;
(void) argv;
return 0;
}

$ gcc -std=c99 -pedantic -Wall -Wextra -Werror -o russel russel.c

russel.c: In function ‘main’:
russel.c:3:18: error: a member of a structure or union cannot have a
variably modified type [-Werror=edantic]
russel.c:4:15: error: a member of a structure or union cannot have a
variably modified type [-Werror=edantic]
cc1: all warnings being treated as errors

That was: gcc version 4.7.2 20120921 (Red Hat 4.7.2-2)

--
- Shao Miller
--
"Thank you for the kind words; those are the kind of words I like to hear.

Cheerily," -- Richard Harter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Variably modified arrays Andrey Tarasevich C Programming 0 01-24-2013 07:12 PM
Re: Variably modified arrays Shao Miller C Programming 0 01-24-2013 04:17 PM
Explanation needed for const int "error: variably modified ... atfile scope." Poster Matt C Programming 21 06-16-2010 05:35 PM
error: parameter may not have variably modified type Helmut Jarausch C++ 20 10-22-2009 11:09 AM
Variably modified struct/union and C99 Foo C Programming 2 10-08-2009 11:54 AM



Advertisments