Function prototype + definition in the same file

Manu turkeyman at gmail.com
Tue Sep 25 07:40:41 PDT 2012


On 25 September 2012 17:25, Steven Schveighoffer <schveiguy at yahoo.com>wrote:

> On Tue, 25 Sep 2012 07:53:17 -0400, Manu <turkeyman at gmail.com> 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++)
>>
>
> Doing this is not illegal.
>
>
>  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
>> }
>>
>
> This compiles.  Do you have a better case to show the problem?
>

void blah();

void  blah()
{
int x = 0;
}

void f()
{
   blah(); // <- call it
}


W:\project\main\sourcedata\plugins\remedy\modules\test_module.d(38):Error:
function remedy.testmodule.blah called with argument types:
(())
matches both:
remedy.testmodule.blah()
and:
remedy.testmodule.blah()

Obviously, one is just a prototype, and the symbol is resolved within the
local file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120925/3b52af3b/attachment.html>


More information about the Digitalmars-d mailing list