Re: declaration in for statement



spygg <behindmeisyou@xxxxxxxxx> writes:

On Oct 1, 12:50 am, Luca Forlizzi <luca.forli...@xxxxxxxxx> wrote:
The declaration part of a for statement is subject to the constraint
given in
Sec. 6.8.5 p3, which says "The declaration part of a for statement
shall only declare identifiers for objects having
storage class auto or register."

DR 277 clarifies that this constraint is violated if the declaration
declare an identifier that
is not an object, like a tag or an enumeration constant.

I was going to leave this alone, but since I am commenting on a comment...

To me (as a non-native english speaker) it is not clear if the
constraint is violated
in the case where the declaration declares a new type without a tag
(if the new
type has a tag, then it clearly violates the constraint because the
tag is an
identifier not denoting an object), like for instance in:

        for (struct { short a[2]; float b; } d = { {0, 0}, 0 }; d.b<10.5; d.b+
+) ...

I'd say the common interpretation is that any declaration of anything
but an identifier for an object (of the right storage class) is a
constraint violation. The key, then, is what is declared by that 'for'
statement?

There is some ambiguity in the meaning of the word "declare". It would
be nice if identifiers were always declared and objects, types and
function were defined. This is a distinction that is common when
talking about programming languages in an abstract way, but it seems
that the C standard does not want to use this distinction. Some
sections talk about declaring is structure type with or without a tag.

The question then hangs on whether 'struct { int i; } d;' declares
anything other than the identifier d. From the language used in, say,
6.2.7 p1 I'd have to say that this declares a structure type as well and
so it does not "only declare identifiers for objects...".

Part of me would like to "correct" the standard and say that 'struct {
int i; } d;' *declares* the identifier 'd' and also *defines* a structure
type at the same time. That's how I'd talk about it, but the meaning of
the word 'declare' is important for 6.8.5 p3 and it seems it includes
what I would casually call a structure type definition.

I put "correct" in quotes because there is nothing wrong with the usage
in the standard. In particular it follows from the fact the a
"declaration" is syntax name that covers everything from function
definitions to external object declarations.

I notice that gcc silently accept this construct, while producing
diagnostics in
cases where is present an identifier not denoting an object with auto
or register
storage class.
Is gcc right?

According to my eexperience " struct { short a[2]; float b; } d =
{ {0, 0}, 0 }; " is just a expression its vaule (as a whole)is 1 or
0

It's a declaration, not an expression. As for the 0 or 1 I don't see
how you come to that conclusion. Are you confusing = with ==?

PS:I am new learner ,just give my opinion and wait for C cattle man^_^

--
Ben.
.



Relevant Pages

  • Re: Shared Objects Libraries and Symbols...
    ... ~ 1 An identifier declared in different scopes or in the same scope more ... There are three kinds of linkage: ... each declaration of an identifier with internal ... ~ 4 For an identifier declared with the storage-class specifier extern ...
    (comp.os.linux.development.apps)
  • Re: Newbie static class member question [C++]
    ... > class declaration, but define them outside of it (as a general ... meaning of an identifier. ... The definition tells the compiler to generate code to allocate memory ... One such namespace is global, ...
    (alt.comp.lang.learn.c-cpp)
  • Namespace problems when compiling (xutility)
    ... I am trying to compile my project with MTL (Matrix Template Library) and I am ... undeclared identifier ...
    (microsoft.public.vc.language)
  • Re: What type is address of an array
    ... char s; ... the identifier is declared with no linkage. ... a compatible declaration of the ... same identifier may occur farther down in the same translation unit ...
    (comp.lang.c.moderated)
  • Re: how to define a function pointer variable witout typdef?
    ... I have N869 and it makes no reference to typedef reserving ... A /definition/ of an identifier is a declaration for that ...
    (comp.lang.c)