Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: is "x *= ++f * ++f" a valid statement ? Date: Tue, 23 Jul 2024 15:05:43 -0700 Organization: None to speak of Lines: 76 Message-ID: <87y15rg3wo.fsf@nosuchdomain.example.com> References: <96127c8d8d204b7c3230828101bc2b6e@www.novabbs.org> <877cdchj2i.fsf@nosuchdomain.example.com> <86ttgg41yb.fsf@linuxsc.com> <8734nzhjkg.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 24 Jul 2024 00:05:43 +0200 (CEST) Injection-Info: dont-email.me; posting-host="a6a186c935bfba1403cc2587b3983622"; logging-data="1448486"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wO+oFl1ncOoq9FxqV8HED" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:vabshdUyIBxvNl+0eD6PrJ8Dzmc= sha1:1INVTUFhD1Lrk6Kf4M0ukSOS4fg= Xref: csiph.com comp.lang.c++:119734 Keith Thompson writes: > Tim Rentsch writes: >> Keith Thompson writes: >> >>> James Kuyper writes: >> [...] >>>> A minor detail is that a variable must be declared, whereas memory >>>> locations can, for instance, be part of allocated memory for which >>>> no declaration exists - it is still undefined behavior to write >>>> code that applies unsequence side-effects to such memory locations. >>> >>> Digression: I'm not even sure what "variable" means in C++. The >>> standard defines the term, but not in a way that really tells us >>> what it means. >>> >>> "A *variable* is introduced by the declaration of a reference other >>> than a non-static data member or of an object. The variable's name, >>> if any, denotes the reference or object." >> >> What part do you find confusing or hard to understand? > > The missing part that should tell us what a variable *is*. > > It says that certain declarations "introduce" a variable. That's a > statement about variables, but it doesn't say what a variable is. > > Given: > > int n; > > we know that the declaration introduces a variable. Is the object > itself a "variable"? That's the obvious meaning, and it's consistent > with what the standard says. Or is a "variable" some kind of logical > binding between an object and a name? That's also consistent with what > the standard says. Under the latter interpretation, the "variable" has > a name, and that name denotes an object, but the variable is not the > object. > > Given the above declaration, is the introduced variable an object? If > so, or if not, how does your answer follow from what the standard says? On further thought, I think the intent has to be that a variable is not an object. A variable is introduced by a declaration, and a declaration is not necessarily a definition. For example, given: int var = 42; int main() { extern int var; } There are two declarations for "var"; only the first is a definition. If I understand correctly, each of these declarations introduces a variable. So apparently there are two variables with the name "var", but only one object. Or is there just one variable that's "introduced" twice? But the following paragraph says: A *local entity* is a variable with automatic storage duration (6.7.5.4), a structured binding (9.6) whose corresponding variable is such an entity, or the *this object (7.5.3). Storage duration is an attribute of objects. If a variable can have automatic storage duration, then apparently a variable is an object. Informally, I think of a "variable" as an object whose name is an identifer. Given `int foo[10];`, foo would be a variable, but foo[1] would not. Perhaps I'm missing something obvious, but I don't know what. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */