bearophile wrote:
Don:
Thank you for bringing up this topic, Don :-)
In D, beside the C syntax for function types, there also is the C syntax for
function pointers. I presume it gives less problems than the first one.
Yes, I included that in the patch as well. It makes them deprecated, so
they compile if and only if the -d command line switch is used.
See also:
http://d.puremagic.com/issues/show_bug.cgi?id=4530
In the past, Walter has mentioned a weak argument for retaining C-style
array declaration syntax, although I personally find it very
unconvincing. But C's hideous function pointer syntax is on a whole
other level. It's really hurting us. I believe it should be deprecated
immediately. But the 'function type' syntax shouldn't be allowed even as
a deprecated syntax. It's horrible.
One of the faults of C++, that increases its useless complexity a lot, is to
have in many cases two ways (the C way and the C++ way) to do something.
Generally the idea of duplicated syntax is bad.
But I have translated lot of C code to D1 and I've seen that the possibility
that D1 gives me to leave matrix definitions as they are helps me reduce the
amount of changes to the C code needed to perform the translation (and I think
this may help avoid some translation bugs, but I have no proof of this).
So I leave declarations like:
int mat[5][16];
And only later, when the D1 programs works correctly, I replace them by code
like:
int[16][5] mat;
To merge such two needs, I have suggested a compilation switch, it may be named
"-cstyle". It's designed to help translation of C code to D. If a module is
compiled with -cstyle then DMD accepts C-style array declarations and C-style functions
pointers, and it also gives warnings against passing by value large fixed-sized arrays
and against the usage of global floating floating values before their initialization
(those are two things that may trip a person that translates C code to D, because D
passes fixed-sized arrays by value and doesn't initialize global floats to 0 but to NaN).
The idea is, when you need to translate C code to D you use the -cstyle switch,
that allows some C syntax and gives those two extra warnings. When your code
works, you may finish the translation to D and stop using the -cstyle switch.
See:
http://d.puremagic.com/issues/show_bug.cgi?id=4580
What kind of error message does your patch gives for 4962?
bug.d(6): function declaration without return type. (Note that
constructors are always named 'this')
That is, it doesn't work out if it was intended to be a constructor, it
gives the same error message for any function with no return type.
Making a dedicated error message for constructors would require
longer-range changes to the parser. But I believe that that the
C++/Java/C# constructor syntax is by far the most common syntax where it
will happen.