Function prototype + definition in the same file

Manu turkeyman at gmail.com
Wed Sep 26 01:14:43 PDT 2012


On 26 September 2012 02:35, Timon Gehr <timon.gehr at gmx.ch> wrote:

> On 09/26/2012 01:29 AM, Timon Gehr wrote:
>
>> On 09/25/2012 01:53 PM, Manu wrote:
>>
>>> So I have this recurring pattern, it's really starting to annoy me.
>>> It stems from the fact that a function prototype and the definition can
>>> not appear in the same file in D (as it can in C/C++)
>>> Eg,
>>>
>>> void func(int x); // <-- declaration of function, informs type and
>>> associated names, args, ...
>>>
>>> //later
>>> void func(int x) // <-- may be generated with magic (and may use the
>>> prototype declaration for type information as declared by the prototype
>>> above)
>>> {
>>>    ... do stuff
>>> }
>>>
>>> I really need this. Why is it illegal? Is there chance of having this
>>> supported? What are the problems?
>>> ...
>>>
>>
>> It is illegal because nobody has written code to support it. It
>> should be possible to support it. I don't think there are any problems
>> with the concept.
>>
>
> (The implementation faces some challenges, the following is easy to get
> wrong:
>
> module module_;
>
> void foo();
>
> alias foo alias1;
> static if(is(typeof(alias1))){
>     void foo(){}
>     alias foo alias2;
> }
>
> static assert(__traits(isSame, alias1, alias2));
> static assert(__traits(allMembers, module_).length == 3); // 2 alias, 1
> function definition
> )
>

I'm not sure I understand the point being illustrated here. I don't see how
the aliases are relevant?
Is an alias to a prototype somehow different than an alias to a definition?

Shouldn't the discovery of a function definition within the same file as a
pre-declared prototype just promote the prototype to a full definition?
They are the same symbol, just that one instance adds the definition.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120926/25f15605/attachment.html>


More information about the Digitalmars-d mailing list