Sujet : Re: C23 auto x C++ auto.
De : already5chosen (at) *nospam* yahoo.com (Michael S)
Groupes : comp.lang.cDate : 26. May 2024, 15:23:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240526172307.00005e3e@yahoo.com>
References : 1
User-Agent : Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
On Sun, 26 May 2024 10:49:30 -0300
Thiago Adams <
thiago.adams@gmail.com> wrote:
I think most people is not aware of this:
From 3096 C23 draft
"
6.7.9 Type inference
...
2 For such a declaration that is the definition of an object the
init- declarator shall have the form
direct-declarator = assignment-expression
"
Basically "direct-declarator" differs from "declarator" because it
does not contains pointer.
Then the type inference using auto and pointer is something undefined
in C23.
struct node{
struct node * next;
};
int main(){
struct node node = {};
auto * p = node.next;
}
<source>:7:4: error: 'auto' requires a plain identifier, possibly
with attributes, as declarator
7 | auto * p = node.next;
| ^~~~
This differs from C++.
Differs in positive way. Less confusing.