We need to kill C syntax for declaring function types
BCS
none at anon.com
Mon Oct 4 06:56:16 PDT 2010
Hello Don,
> Steven Schveighoffer wrote:
>
>> On Mon, 04 Oct 2010 05:07:07 -0400, Don <nospam at nospam.com> wrote:
>>
>>> A great example of how C syntax is hurting us.
>>> ---
>>> I found this bit of code in std.container, inside BinaryHeap:
>>> size_t insert(ElementType!Store value)
>>> {
>>> static if (is(_store.insertBack(value)))
>>> {
>>> ...
>>> }
>>> else ...
>>> What does the static if do? It's *intended* to check if _store has a
>>> member function insertBack(), which accepts type of a 'value'.
>>>
>>> But instead, it ALWAYS silently does the 'else' clause.
>>> Unless _store.insertBack is a valid *type*, (eg, alias int
>>> insertBack;).
>>> In which case it gives an error "declaration value is already
>>> defined".
>> I'm really confused here. I could have sworn I've seen compile time
>> checks like this everywhere. Is the "bug" that's unflagged by the
>> compiler that you are missing a typeof(...)?
>>
> Yes.
>
>>> Why?
>>>
>>> This happens because
>>> x(y); is valid C syntax for declaring a type 'y', such that &y is of
>>> type 'x function()'.
>> Wait, I thought when declaring a function pointer, you had to have
>> the (*) in there? Plus I thought you had to have an extra set of
>> parentheses? I've never seen this before.
>>
>> Trying...
>>
>> Oh, that's freaking awful. x(y); silently compiles into something
>> useless, you need to declare it with a typedef in order to use it
>> (and even then, it's horrible). It's like accepting the line
>>
>> int;
>>
>> Yes, 100% agree, get rid of this. Does that mean we need to get rid
>> of C-style function pointer declarations? Because I recently saw a
>> use for them (deciphering C-style function pointer syntax).
>>
> I agree, I use it for the same thing. In the patch, I made C-style
> function pointers deprecated (so you can still compile it with the -d
> switch) and C-style abominable x(y) types illegal.
>
> I would expect that it always remains a deprecated syntax, to aid
> conversion of C-style code. But in my experience, you always want to
> get rid of them eventually.
>
I.e. the use of C-style function pointer syntax is deprecated, the syntax
it self is not. Got it, nice.
--
... <IXOYE><
More information about the Digitalmars-d
mailing list