Re: C2X Proposal, merge '.' and '->' C operators
On 12/16/19, J Decker wrote: > Here's the gist of what I would propose... > https://gist.github.com/d3x0r/f496d0032476ed8b6f980f7ed31280da > > In C, there are two operators . and -> used to access members of struct and > union types. These operators are specified such that they are always paired > in usage; for example, if the left hand expression is a pointer to a struct > or union, then the operator -> MUST be used. There is no occasion where . > and -> may be interchanged, given the existing specification. > > It should be very evident to the compiler whether the token before '.' or > '->' is a pointer to a struct/union or a struct/union, and just build the > appropriate output. I have mixed feelings on this proposal. On the one hand, when I was first learning C, the difference between '.' and '->' was a major source of confusion (as was understanding pointers in general). On the other hand, now that I understand them a bit better, I find the distinction to be helpful in reducing ambiguity and making code more readable. > > The source modification for the compiler is very slight, even depending on > flag_c2x(that's not it's name). It ends up changing a lot of existing > lines, just to change their indentation; but that shouldn't really count > against 'changed lines'. > > I'm sure, after 4 score and some years ('78-19) that it must surely have > come up before? Anyone able to point me to those existing proposals? I saw some Twitter threads and StackOverflow Q&As on the topic before; I'm not really sure how to search to find them again though, given that the punctuation involved is often treated as special characters... > > D >
Re: C2X Proposal, merge '.' and '->' C operators
On Mon, Dec 16, 2019 at 5:52 AM J Decker wrote: > > Here's the gist of what I would propose... > https://gist.github.com/d3x0r/f496d0032476ed8b6f980f7ed31280da > > In C, there are two operators . and -> used to access members of struct and > union types. These operators are specified such that they are always paired > in usage; for example, if the left hand expression is a pointer to a struct > or union, then the operator -> MUST be used. There is no occasion where . > and -> may be interchanged, given the existing specification. > > It should be very evident to the compiler whether the token before '.' or > '->' is a pointer to a struct/union or a struct/union, and just build the > appropriate output. > > The source modification for the compiler is very slight, even depending on > flag_c2x(that's not it's name). It ends up changing a lot of existing > lines, just to change their indentation; but that shouldn't really count > against 'changed lines'. > > I'm sure, after 4 score and some years ('78-19) that it must surely have > come up before? Anyone able to point me to those existing proposals? For what it's worth, that is how Go works. The '.' operator is used for struct fields regardless of whether the left hand operand is a struct or a pointer to a struct. Ian
Re: C2X Proposal, merge '.' and '->' C operators
On Monday, 16 December 2019 14:51:38 CET J Decker wrote: > Here's the gist of what I would propose... > https://gist.github.com/d3x0r/f496d0032476ed8b6f980f7ed31280da > > In C, there are two operators . and -> used to access members of struct and > union types. These operators are specified such that they are always paired > in usage; for example, if the left hand expression is a pointer to a struct > or union, then the operator -> MUST be used. There is no occasion where . > and -> may be interchanged, given the existing specification. > > It should be very evident to the compiler whether the token before '.' or > '->' is a pointer to a struct/union or a struct/union, and just build the > appropriate output. > > The source modification for the compiler is very slight, even depending on > flag_c2x(that's not it's name). It ends up changing a lot of existing > lines, just to change their indentation; but that shouldn't really count > against 'changed lines'. > > I'm sure, after 4 score and some years ('78-19) that it must surely have > come up before? Anyone able to point me to those existing proposals? > What if you operate on a pointer to a pointer to a struct? Should the same operator just magically dereference everything until it is a struct? I disagree with this proposal because separate a thing and a pointer to a thing is fundamental to C/C++, and providing short-cuts that confuse the two is doing a disservice to anyone that needs to learn it. Besides isn't this the wrong mailing list for this? 'Allan
gcc-9-20191221 is now available
Snapshot gcc-9-20191221 is now available on https://gcc.gnu.org/pub/gcc/snapshots/9-20191221/ and on various mirrors, see http://gcc.gnu.org/mirrors.html for details. This snapshot has been generated from the GCC 9 SVN branch with the following options: svn://gcc.gnu.org/svn/gcc/branches/gcc-9-branch revision 279700 You'll find: gcc-9-20191221.tar.xzComplete GCC SHA256=10e69a8a54dda9d10f49a557b62bcfbb865f5ccc3b5a52d8ef2f38524df83b4b SHA1=cadd78aafda41c2c7092607a82d7f78a501e8723 Diffs from 9-20191214 are available in the diffs/ subdirectory. When a particular snapshot is ready for public consumption the LATEST-9 link is updated and a message is sent to the gcc list. Please do not use a snapshot before it has been announced that way.
Re: C2X Proposal, merge '.' and '->' C operators
> For what it's worth, that is how Go works. The '.' operator is used > for struct fields regardless of whether the left hand operand is a > struct or a pointer to a struct. Likewise in Ada. -- Eric Botcazou