Puzzled by this behavior

Steven Schveighoffer schveiguy at gmail.com
Tue May 31 20:47:36 UTC 2022


On 5/31/22 4:33 PM, Ola Fosheim Grøstad wrote:
> On Tuesday, 31 May 2022 at 20:24:17 UTC, Steven Schveighoffer wrote:
> 
>> ```d
>>     void foo() {bar(); }; // redeclares foo, not allowed
>> ```
> 
> This ought to define what has already been declared. That is the purpose 
> of a prototype. Calling this a "redeclaration" is arbitrary.

I don't know why it does that, I assume Walter has a good reason for 
that. But they do work at module level (which is kinda weird, since you 
don't need them there). I had thought they weren't allowed.

>> You can't "assign" functions like you can lambdas. And D does not 
>> allow redeclaring a symbol of any type in a specific scope.
> 
> Why do you call it "redeclaring" the signature is the same!? That's just 
> an after-the-fact explanation. Calling this redeclaring doesn't follow 
> from how prototypes in C works. If the signature is the same then you 
> can do it as many times as you want.

I can't do:

```d
int x;
int x = 5;
```

So I assume it's similar to declaring functions, but I don't know the 
reason it allows this for function prototypes at the module level.

-Steve


More information about the Digitalmars-d mailing list