www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Function prototype + definition in the same file

reply Manu <turkeyman gmail.com> writes:
--047d7b339229103dce04ca855a6a
Content-Type: text/plain; charset=UTF-8

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?

My problem is essentially to do with supporting both static or dynamic
linkage optionally, but it also shows up in situations where I want to
perform comprehensive magic code generation, but want clear-readable user
declarations.
The simplest case:
  I have an extern that I may want to statically or dynamically link.
    In the case of static linkage, one just produces a prototype, and it
links, no problem.
    In the case of dynamic linkage, one must produce a stub for the
function, a function pointer to call through, and perhaps some code to
hook-up the function pointer at init.

I have a fairly comprehensive binding solution which automates the work in
the case of dynamic linkage, but the problem is the way the user defines
the functions that exist in the D code.
I'd like it if the users would just write the prototypes, they'd be easily
readable, simple to create by cutting and pasting straight from C code. And
when statically linking, it would just work, the module hook-up mixin does
nothing in this configuration.
In the case of dynamic linkage, a single hook-up mixin in the file
somewhere could scan the module for these prototypes and generate the
stubs, function pointers, and the boot-up code that would connect them
(while validating their signatures against the extern import table, etc).

This approach isn't supported though. What I do instead:

mixin( ImportFunction!( "functionName", int function( int arg1, float arg2,
ref in SomeStruct arg3 ), "pure nothrow" ) );
mixin( ImportFunction!( "functionName2", int function() ) );
mixin( ImportFunction!( "functionName3", int function( int x, int y ),
"nothrow" ) );
etc etc

These templates produce, from the information provided, either a prototype
for static linkage, or the { stub, func pointer, initialisation info } for
dynamic linkage.

I really don't like doing it this way for a number of reasons:
  *** This results in hundreds of mixins, which quickly lead to intolerable
compile times (to the point where D is losing it's appeal as a viable
choice for our needs). If done my preferred way, I could do the magic with
a single mixin at the bottom of the file.
  * It's barely readable.
  * Much more annoying to write and maintain when the counterpart API
changes, and is more error-prone.
  * IDE features don't work properly; syntax highlighting, hover info,
go-to-definition, etc.

I also have numerous more advanced cases of the same problem, and becomes
even more unsightly when used in structs to emulate dynamic linkage to
static methods of C++ classes.

The solution is seemingly trivial; allow function prototypes and
definitions to exist in the same file, like in C/C++.


Go on, tear me apart... :)

--047d7b339229103dce04ca855a6a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

So I have this recurring pattern, it&#39;s really starting to annoy me.<div=
It stems from the fact that a function prototype and the definition can no=


type and associated names, args, ...</div><div><br></div><div>//later</div=
<div>void func(int x) // &lt;-- may be generated with magic (and may use t=

above)</div> <div>{</div><div>=C2=A0 ... do stuff</div><div>}</div><div><br></div><div>I= really need this. Why is it illegal? Is there chance of having this suppor= ted? What are the problems?</div><div><br></div><div>My problem is essentia= lly to do with supporting both static or dynamic linkage optionally, but it= also shows up in situations where I want to perform comprehensive magic co= de generation, but want clear-readable user declarations.</div> <div>The simplest case:</div><div>=C2=A0 I have an extern that I may want t= o statically or dynamically link.</div><div>=C2=A0 =C2=A0 In the case of st= atic linkage, one just produces a prototype, and it links, no problem.</div=
<div>=C2=A0 =C2=A0 In the case of dynamic linkage, one must produce a stub=

e to hook-up the function pointer at init.</div> <div><br></div><div>I have a fairly comprehensive binding solution which au= tomates the work in the case of dynamic linkage, but the problem is the way= the user defines the functions that exist in the D code.</div><div>I&#39;d= like it if the users would just write the prototypes, they&#39;d be easily= readable, simple to create by cutting and pasting straight from C code. An= d when statically linking, it would just work, the module hook-up mixin doe= s nothing in this configuration.</div> <div>In the case of dynamic linkage, a single hook-up mixin in the file som= ewhere could scan the module for these prototypes and generate the stubs, f= unction pointers, and the boot-up code that would connect them (while valid= ating their signatures against the extern import table, etc).</div> <div><br></div><div>This approach isn&#39;t supported though. What I do ins= tead:</div><div><br></div><div>mixin( ImportFunction!( &quot;functionName&q= uot;, int function( int arg1, float arg2, ref in SomeStruct arg3 ), &quot;p= ure nothrow&quot; ) );</div> <div>mixin( ImportFunction!( &quot;functionName2&quot;, int function() ) ); </div><div>mixin( ImportFunction!( &quot;functionName3&quot;, int function(= int x, int y ), &quot;nothrow&quot; ) ); </div><div>etc etc</div><div><br></div><div>These templates produce, from t= he information provided, either a prototype for static linkage, or the { st= ub, func pointer, initialisation info } for dynamic linkage.</div><div> <br></div><div>I really don&#39;t like doing it this way for a number of re= asons:</div><div>=C2=A0 *** This results in hundreds of mixins, which quick= ly lead to intolerable compile times (to the point where D is losing it&#39= ;s appeal as a viable choice for our needs). If done my preferred way, I co= uld do the magic with a single mixin at the bottom of the file.</div> <div>=C2=A0 * It&#39;s barely readable.</div><div>=C2=A0 * Much more annoyi= ng to write and maintain when the counterpart API changes, and is more erro= r-prone.</div><div>=C2=A0 * IDE features don&#39;t work properly; syntax hi= ghlighting, hover info, go-to-definition, etc.</div> <div><br></div><div>I also have numerous more advanced cases of the same pr= oblem, and becomes even more unsightly when used in structs to emulate dyna= mic linkage to static methods of C++ classes.</div><div><br></div><div> The solution is seemingly trivial; allow function prototypes and definition= s to exist in the same file, like in C/C++.</div><div><br></div><div><br></= div><div>Go on, tear me apart... :)</div> --047d7b339229103dce04ca855a6a--
Sep 25 2012
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Manu:

 I have a fairly comprehensive binding solution which automates 
 the work in
 the case of dynamic linkage, but the problem is the way the 
 user defines the functions that exist in the D code.

Maybe there are better ways to solve your problems (even changing D language in some ways), and keep avoiding the need of free floating ghosts of functions. Bye, bearophile
Sep 25 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--047d7b33d36684a50404ca85d22c
Content-Type: text/plain; charset=UTF-8

On 25 September 2012 15:21, bearophile <bearophileHUGS lycos.com> wrote:

 Manu:


  I have a fairly comprehensive binding solution which automates the work in
 the case of dynamic linkage, but the problem is the way the user defines
 the functions that exist in the D code.

Maybe there are better ways to solve your problems (even changing D language in some ways), and keep avoiding the need of free floating ghosts of functions.

Can you suggest a more direct approach? Declaring prototypes seems completely natural, supports all the expected IDE features, and in the simple/common case (static linkage) requires absolutely no magic voodoo. --047d7b33d36684a50404ca85d22c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 25 September 2012 15:21, bearophile <span dir= =3D"ltr">&lt;<a href=3D"mailto:bearophileHUGS lycos.com" target=3D"_blank">= bearophileHUGS lycos.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmai= l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left= :1ex"> Manu:<div class=3D"im"><br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> I have a fairly comprehensive binding solution which automates the work in<= br> the case of dynamic linkage, but the problem is the way the user defines th= e functions that exist in the D code.<br> </blockquote> <br></div> Maybe there are better ways to solve your problems (even changing D languag= e in some ways), and keep avoiding the need of free floating ghosts of func= tions.<br></blockquote><div><br></div><div>Can you suggest a more direct ap= proach? Declaring prototypes seems completely natural, supports all the exp= ected IDE features, and in the simple/common case (static linkage) requires= absolutely no magic voodoo.</div> </div> --047d7b33d36684a50404ca85d22c--
Sep 25 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 25 Sep 2012 07:53:17 -0400, Manu <turkeyman 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? -Steve
Sep 25 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--20cf307f3a9ebd2c4c04ca87b076
Content-Type: text/plain; charset=UTF-8

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

 On Tue, 25 Sep 2012 07:53:17 -0400, Manu <turkeyman 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. --20cf307f3a9ebd2c4c04ca87b076 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 25 September 2012 17:25, Steven Schveighoffer= <span dir=3D"ltr">&lt;<a href=3D"mailto:schveiguy yahoo.com" target=3D"_bl= ank">schveiguy yahoo.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmai= l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left= :1ex"> <div class=3D"im">On Tue, 25 Sep 2012 07:53:17 -0400, Manu &lt;<a href=3D"m= ailto:turkeyman gmail.com" target=3D"_blank">turkeyman gmail.com</a>&gt; wr= ote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> So I have this recurring pattern, it&#39;s really starting to annoy me.<br> It stems from the fact that a function prototype and the definition can not= <br> appear in the same file in D (as it can in C/C++)<br> </blockquote> <br></div> Doing this is not illegal.<div class=3D"im"><br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Eg,<br> <br> void func(int x); // &lt;-- declaration of function, informs type and<br> associated names, args, ...<br> <br> //later<br> void func(int x) // &lt;-- may be generated with magic (and may use the<br> prototype declaration for type information as declared by the prototype<br> above)<br> {<br> =C2=A0 ... do stuff<br> }<br> </blockquote> <br></div> This compiles. =C2=A0Do you have a better case to show the problem?<br></bl= ockquote><div><br></div><div><div>void blah();</div><div><br></div><div>voi= d=C2=A0 blah()</div><div>{</div><div><span class=3D"Apple-tab-span" style=3D"white-= space:pre"> </span>int x =3D 0;</div><div>}</div></div><div><br></div><div>= void f()</div><div>{</div><div>=C2=A0 =C2=A0blah(); // &lt;- call it</div><= div>}</div> <div><br></div><div><br></div><div><div>W:\project\main\sourcedata\plugins\= remedy\modules\test_module.d(38):Error: function remedy.testmodule.blah=C2= =A0called with argument types:</div><div><span class=3D"Apple-tab-span" sty= le=3D"white-space:pre"> </span>(())</div> <div>matches both:</div><div><span class=3D"Apple-tab-span" style=3D"white-= space:pre"> </span>remedy.testmodule.blah()</div><div>and:</div><div><span = class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>remedy.testmodul= e.blah()</div> </div><div><br></div><div>Obviously, one is just a prototype, and the symbo= l is resolved within the local file.</div></div> --20cf307f3a9ebd2c4c04ca87b076--
Sep 25 2012
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-09-25 13:53, Manu wrote:

 I really don't like doing it this way for a number of reasons:
    *** This results in hundreds of mixins, which quickly lead to
 intolerable compile times (to the point where D is losing it's appeal as
 a viable choice for our needs). If done my preferred way, I could do the
 magic with a single mixin at the bottom of the file.

I guess you already figured this out but a single mixin with a lot of code is a lot faster than several mixins with little code. Although this will decrease the readability even further. -- /Jacob Carlborg
Sep 25 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 25 Sep 2012 10:40:41 -0400, Manu <turkeyman gmail.com> wrote:

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

 On Tue, 25 Sep 2012 07:53:17 -0400, Manu <turkeyman 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()

Oh, that is funny. I simply compiled the functions and didn't call them, assuming if that compiled it was legal. This is definitely a bug. In fact you can implement a function *twice* and this isn't an error. Check this out: testme2.d: module testme2; import std.stdio; void foo() { writeln("first"); } void foo() { writeln("second"); } testme2.di: module testme2; void foo(); testme.d: import testme2; void main() { foo(); } Compile like this: dmd -c testme2.d dmd testme.d testme2.o links, and when I run, it displays: first So clearly there isn't something right here, that should definitely be an error. I think there are two errors here. First, the spec does not say you cannot prototype a function before declaring it. All it says is: Functions without bodies: int foo(); that are not declared as abstract are expected to have their implementations elsewhere, and that implementation will be provided at the link step. This enables an implementation of a function to be completely hidden from the user of it, and the implementation may be in another language such as C, assembler, etc. from: http://dlang.org/function.html I don't see any rules that would preclude pre-declaring a prototype, even if it's not promoted to do this (after all, forward references should always work, right?). Second, you should not be able to compile two identically prototyped functions with bodies into an object file, I have no idea how that even works. -Steve
Sep 25 2012
prev sibling next sibling parent reply deadalnix <deadalnix gmail.com> writes:
Le 25/09/2012 13:53, Manu a écrit :
 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?

 My problem is essentially to do with supporting both static or dynamic
 linkage optionally, but it also shows up in situations where I want to
 perform comprehensive magic code generation, but want clear-readable
 user declarations.
 The simplest case:
    I have an extern that I may want to statically or dynamically link.
      In the case of static linkage, one just produces a prototype, and
 it links, no problem.
      In the case of dynamic linkage, one must produce a stub for the
 function, a function pointer to call through, and perhaps some code to
 hook-up the function pointer at init.

 I have a fairly comprehensive binding solution which automates the work
 in the case of dynamic linkage, but the problem is the way the user
 defines the functions that exist in the D code.
 I'd like it if the users would just write the prototypes, they'd be
 easily readable, simple to create by cutting and pasting straight from C
 code. And when statically linking, it would just work, the module
 hook-up mixin does nothing in this configuration.
 In the case of dynamic linkage, a single hook-up mixin in the file
 somewhere could scan the module for these prototypes and generate the
 stubs, function pointers, and the boot-up code that would connect them
 (while validating their signatures against the extern import table, etc).

 This approach isn't supported though. What I do instead:

 mixin( ImportFunction!( "functionName", int function( int arg1, float
 arg2, ref in SomeStruct arg3 ), "pure nothrow" ) );
 mixin( ImportFunction!( "functionName2", int function() ) );
 mixin( ImportFunction!( "functionName3", int function( int x, int y ),
 "nothrow" ) );
 etc etc

 These templates produce, from the information provided, either a
 prototype for static linkage, or the { stub, func pointer,
 initialisation info } for dynamic linkage.

 I really don't like doing it this way for a number of reasons:
    *** This results in hundreds of mixins, which quickly lead to
 intolerable compile times (to the point where D is losing it's appeal as
 a viable choice for our needs). If done my preferred way, I could do the
 magic with a single mixin at the bottom of the file.
    * It's barely readable.
    * Much more annoying to write and maintain when the counterpart API
 changes, and is more error-prone.
    * IDE features don't work properly; syntax highlighting, hover info,
 go-to-definition, etc.

 I also have numerous more advanced cases of the same problem, and
 becomes even more unsightly when used in structs to emulate dynamic
 linkage to static methods of C++ classes.

 The solution is seemingly trivial; allow function prototypes and
 definitions to exist in the same file, like in C/C++.


 Go on, tear me apart... :)

This is code duplication and is generally considered as a bad practice. I'm not convinced that the language should be modified to allow something that is known as bad practice. What you need here is a more robust di generator IMO.
Sep 25 2012
parent reply deadalnix <deadalnix gmail.com> writes:
Le 25/09/2012 20:57, Maxim Fomin a écrit :
 On Tuesday, 25 September 2012 at 17:48:46 UTC, deadalnix wrote:
 This is code duplication and is generally considered as a bad
 practice. I'm not convinced that the language should be modified to
 allow something that is known as bad practice.

 What you need here is a more robust di generator IMO.

This is neither a code duplication (there is certain distinction between prototype and body) nor a bad practice - this is a common pattern in C and C++. It is surprising that D cannot do such a simple thing which in addition is not harmless, so there is no sense in depreciating it.

This is code duplication. And this has been considered a problem in C/C++ for a while now.
Sep 25 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-09-25 22:07, Jonathan M Davis wrote:

 I'd argue that the fact that prototypes are part of the language is
 a sign of a deficiency in the language (especially if they're necessary).

They're necessary for linking with C functions. But except from that I agree with you. -- /Jacob Carlborg
Sep 25 2012
prev sibling parent deadalnix <deadalnix gmail.com> writes:
Le 25/09/2012 22:43, Steven Schveighoffer a écrit :
 But I think what Manu is trying to do is not exactly just "repeat the
 signature", he is using the signature of the original to generate the
 signature of the auto-generated function. Essentially, it's not
 duplicated code on either the source or the compiled level, so disabling
 the ability to declare a function and then implement it later would
 prevent this possibility. I don't think it makes sense to do that.

This is why I suggested to improve the di generator instead of allowing that in the language in a first place.
Sep 26 2012
prev sibling next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Tuesday, 25 September 2012 at 17:48:46 UTC, deadalnix wrote:
 This is code duplication and is generally considered as a bad 
 practice. I'm not convinced that the language should be 
 modified to allow something that is known as bad practice.

 What you need here is a more robust di generator IMO.

This is neither a code duplication (there is certain distinction between prototype and body) nor a bad practice - this is a common pattern in C and C++. It is surprising that D cannot do such a simple thing which in addition is not harmless, so there is no sense in depreciating it.
Sep 25 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 25 Sep 2012 15:23:50 -0400, deadalnix <deadalnix gmail.com> wrot=
e:

 Le 25/09/2012 20:57, Maxim Fomin a =C3=A9crit :
 On Tuesday, 25 September 2012 at 17:48:46 UTC, deadalnix wrote:
 This is code duplication and is generally considered as a bad
 practice. I'm not convinced that the language should be modified to
 allow something that is known as bad practice.

 What you need here is a more robust di generator IMO.

This is neither a code duplication (there is certain distinction betw=


 prototype and body) nor a bad practice - this is a common pattern in =


 and C++. It is surprising that D cannot do such a simple thing which =


 addition is not harmless, so there is no sense in depreciating it.

This is code duplication. And this has been considered a problem in =

 C/C++ for a while now.

No, it's a prototype. Note that it's *required* if you want to hide implementation using .di = files. There is no code involved, it's just generating a symbol reference in th= e = object file. -Steve
Sep 25 2012
prev sibling next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, September 25, 2012 15:48:11 Steven Schveighoffer wrote:
 On Tue, 25 Sep 2012 15:23:50 -0400, deadalnix <deadalnix gmail.com> wrote:
 Le 25/09/2012 20:57, Maxim Fomin a écrit :
 On Tuesday, 25 September 2012 at 17:48:46 UTC, deadalnix wrote:
 This is code duplication and is generally considered as a bad
 practice. I'm not convinced that the language should be modified to
 allow something that is known as bad practice.
 
 What you need here is a more robust di generator IMO.

This is neither a code duplication (there is certain distinction between prototype and body) nor a bad practice - this is a common pattern in C and C++. It is surprising that D cannot do such a simple thing which in addition is not harmless, so there is no sense in depreciating it.

This is code duplication. And this has been considered a problem in C/C++ for a while now.

No, it's a prototype. Note that it's *required* if you want to hide implementation using .di files. There is no code involved, it's just generating a symbol reference in the object file.

It's still code duplication, because you've now listed the function signature twice. Yes, it's minimal code duplication, but it's still duplicating code. It's necessary for stuff like .di files (which are code duplication by definition, because they're duplicating a module - or at least part of it), but most everyone I know has thought (where it's come anyway) that prototypes were a _bad_ thing about C/C++. So, eliminating them as much as possible would generally be good, and even when it comes to .di files, given their limitations (e.g. disabling inlining and CTFE), we arguably should have a better solution for interface files anyway (e.g. having a binary file with the partially compiled code and generated documentation alongside it giving the API), in which case we wouldn't even need prototypes for interface files anymore. If anything, I'd argue that the fact that prototypes are part of the language is a sign of a deficiency in the language (especially if they're necessary). - Jonathan M Davis
Sep 25 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 25 Sep 2012 16:07:51 -0400, Jonathan M Davis <jmdavisProg gmx.co=
m>  =

wrote:

 On Tuesday, September 25, 2012 15:48:11 Steven Schveighoffer wrote:
 On Tue, 25 Sep 2012 15:23:50 -0400, deadalnix <deadalnix gmail.com>  =


 wrote:
 Le 25/09/2012 20:57, Maxim Fomin a =C3=A9crit :
 On Tuesday, 25 September 2012 at 17:48:46 UTC, deadalnix wrote:
 This is code duplication and is generally considered as a bad
 practice. I'm not convinced that the language should be modified =





 allow something that is known as bad practice.

 What you need here is a more robust di generator IMO.

This is neither a code duplication (there is certain distinction =




 between
 prototype and body) nor a bad practice - this is a common pattern =




 C
 and C++. It is surprising that D cannot do such a simple thing whi=




 in
 addition is not harmless, so there is no sense in depreciating it.=




 This is code duplication. And this has been considered a problem in=



 C/C++ for a while now.

No, it's a prototype. Note that it's *required* if you want to hide implementation using .d=


 files.

 There is no code involved, it's just generating a symbol reference in=


 the
 object file.

It's still code duplication, because you've now listed the function =

 signature
 twice. Yes, it's minimal code duplication, but it's still duplicating =

 code.

I misunderstood, I was thinking in terms of generated code. But in any case, it's still not duplicated code. What you are doing is = = defining an interface, then attaching the implementation of the interfac= e = to the declaration by repeating its name. Would you say repeating the function signature of an interface in an = implementing class is code duplication? Would you say that typing the = name of a variable that you already declared so you could access it is = code duplication? Duplicated or not, it's still valid under the spec as far as I can tell.=
 It's necessary for stuff like .di files (which are code duplication by=

 definition, because they're duplicating a module - or at least part of=

 it), but
 most everyone I know has thought (where it's come anyway) that  =

 prototypes were
 a _bad_ thing about C/C++.

The main reason for having prototypes in C/C++ was so you could declare = a = symbol that you weren't defining yet. In some cases, this was necessary, because C/C++ does not have forward = references. So there is indeed very little reason in D to declare a = function, then implement it in the same file. But I think what Manu is trying to do is not exactly just "repeat the = signature", he is using the signature of the original to generate the = signature of the auto-generated function. Essentially, it's not = duplicated code on either the source or the compiled level, so disabling= = the ability to declare a function and then implement it later would = prevent this possibility. I don't think it makes sense to do that. -Steve
Sep 25 2012
prev sibling next sibling parent "Jesse Phillips" <Jessekphillips+D gmail.com> writes:
On Tuesday, 25 September 2012 at 11:52:38 UTC, 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++)
 [...]
 Go on, tear me apart... :)

I'm not sure I understand what benefit you are giving, I'll explain a situation I went through. tldr: I like having a clean "header" file for static linking. It would be nice to build off that to dynamically link. I wanted to load up a DLL (C++ with C interface). Found this nifty file on stackoverflow http://stackoverflow.com/questions/3818229/loading-plugins-dlls-on-the-fly Didn't want to write all those mixins myself. I already had the "header" file for my DLL and didn't want to write all those mixins. I created an array with all the function names, then created a function which took iterated this array and asked for the function type as I'd imported the "header." I ran into a bunch of runtime errors with this setup, probably didn't like the duplication of function names. Or something completely different. Finally I went to static linking. Since I had a nice clean header I didn't need to do anything fancy, pragma(lib) my .lib file and disable the defFunctions mixin.
Sep 25 2012
prev sibling next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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.
Sep 25 2012
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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 )
Sep 25 2012
parent reply deadalnix <deadalnix gmail.com> writes:
Le 26/09/2012 10:14, Manu a écrit :
 On 26 September 2012 02:35, Timon Gehr <timon.gehr gmx.ch
 <mailto:timon.gehr 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?

From a compiler perspective, the example above is hell. That was his point. In other terms, supporting such a feature add complexity to the compiler, and it should come with a sufficient benefice to make sense to implement.
Sep 26 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-09-26 12:19, Manu wrote:

 I can't imagine why the example above is hell, but I know nothing about
 the compiler.

 I have no idea how the existing bug was implemented, but it needs to be
 fixed one way or another.
 It sounds fairly trivial to me to promote a prototype to a definition if
 a definition is found later in the same module.

If the definition is found first, just ignore the prototype? -- /Jacob Carlborg
Sep 26 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--047d7bf0f14e44755004ca966aaa
Content-Type: text/plain; charset=UTF-8

On 26 September 2012 02:35, Timon Gehr <timon.gehr 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. --047d7bf0f14e44755004ca966aaa Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 26 September 2012 02:35, Timon Gehr <span dir= =3D"ltr">&lt;<a href=3D"mailto:timon.gehr gmx.ch" target=3D"_blank">timon.g= ehr gmx.ch</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style= =3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"HOEnZb"><div class=3D"h5">On 09/26/2012 01:29 AM, Timon Gehr = wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> On 09/25/2012 01:53 PM, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> So I have this recurring pattern, it&#39;s really starting to annoy me.<br> It stems from the fact that a function prototype and the definition can<br> not appear in the same file in D (as it can in C/C++)<br> Eg,<br> <br> void func(int x); // &lt;-- declaration of function, informs type and<br> associated names, args, ...<br> <br> //later<br> void func(int x) // &lt;-- may be generated with magic (and may use the<br> prototype declaration for type information as declared by the prototype<br> above)<br> {<br> =C2=A0 =C2=A0... do stuff<br> }<br> <br> I really need this. Why is it illegal? Is there chance of having this<br> supported? What are the problems?<br> ...<br> </blockquote> <br> It is illegal because nobody has written code to support it. It<br> should be possible to support it. I don&#39;t think there are any problems<= br> with the concept.<br> </blockquote> <br></div></div> (The implementation faces some challenges, the following is easy to get wro= ng:<br> <br> module module_;<br> <br> void foo();<br> <br> alias foo alias1;<br> static if(is(typeof(alias1))){<br> =C2=A0 =C2=A0 void foo(){}<br> =C2=A0 =C2=A0 alias foo alias2;<br> }<br> <br> static assert(__traits(isSame, alias1, alias2));<br> static assert(__traits(allMembers, module_).length =3D=3D 3); // 2 alias, 1= function definition<br> )<br> </blockquote></div><br><div>I&#39;m not sure I understand the point being i= llustrated here. I don&#39;t see how the aliases are relevant?</div><div>Is= an alias to a prototype somehow different than an alias to a definition?</= div> <div><br></div><div>Shouldn&#39;t the discovery of a function definition wi= thin the same file as a pre-declared prototype just promote the prototype t= o a full definition? They are the same symbol, just that one instance adds = the definition.</div> --047d7bf0f14e44755004ca966aaa--
Sep 26 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--20cf307f3ba28bb1e804ca982774
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 26 September 2012 13:09, deadalnix <deadalnix gmail.com> wrote:

 Le 26/09/2012 10:14, Manu a =C3=A9crit :

 On 26 September 2012 02:35, Timon Gehr <timon.gehr gmx.ch
 <mailto:timon.gehr 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 =3D=3D 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?

From a compiler perspective, the example above is hell. That was his poin=

 In other terms, supporting such a feature add complexity to the compiler,
 and it should come with a sufficient benefice to make sense to implement.

I can't imagine why the example above is hell, but I know nothing about the compiler. I have no idea how the existing bug was implemented, but it needs to be fixed one way or another. It sounds fairly trivial to me to promote a prototype to a definition if a definition is found later in the same module. --20cf307f3ba28bb1e804ca982774 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 26 September 2012 13:09, deadalnix <span dir= =3D"ltr">&lt;<a href=3D"mailto:deadalnix gmail.com" target=3D"_blank">deada= lnix gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Le 26/09/2012 10:14, Manu a =C3=A9crit :<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><div class=3D"im"> On 26 September 2012 02:35, Timon Gehr &lt;<a href=3D"mailto:timon.gehr gmx= .ch" target=3D"_blank">timon.gehr gmx.ch</a><br></div><div><div class=3D"h5= "> &lt;mailto:<a href=3D"mailto:timon.gehr gmx.ch" target=3D"_blank">timon.geh= r gmx.ch</a>&gt;&gt; wrote:<br> <br> =C2=A0 =C2=A0 On 09/26/2012 01:29 AM, Timon Gehr wrote:<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 On 09/25/2012 01:53 PM, Manu wrote:<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 So I have this recurring pattern,= it&#39;s really starting to<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 annoy me.<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 It stems from the fact that a fun= ction prototype and the<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 definition can<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 not appear in the same file in D = (as it can in C/C++)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Eg,<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 void func(int x); // &lt;-- decla= ration of function, informs<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 type and<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 associated names, args, ...<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 //later<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 void func(int x) // &lt;-- may be= generated with magic (and may<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 use the<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 prototype declaration for type in= formation as declared by<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 the prototype<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 above)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ... do stuff<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 I really need this. Why is it ill= egal? Is there chance of<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 having this<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 supported? What are the problems?= <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ...<br> <br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 It is illegal because nobody has written code t= o support it. It<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 should be possible to support it. I don&#39;t t= hink there are any<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 problems<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 with the concept.<br> <br> <br> =C2=A0 =C2=A0 (The implementation faces some challenges, the following is e= asy to<br> =C2=A0 =C2=A0 get wrong:<br> <br> =C2=A0 =C2=A0 module module_;<br> <br> =C2=A0 =C2=A0 void foo();<br> <br> =C2=A0 =C2=A0 alias foo alias1;<br> =C2=A0 =C2=A0 static if(is(typeof(alias1))){<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0void foo(){}<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0alias foo alias2;<br> =C2=A0 =C2=A0 }<br> <br> =C2=A0 =C2=A0 static assert(__traits(isSame, alias1, alias2));<br> =C2=A0 =C2=A0 static assert(__traits(allMembers, module_).length =3D=3D 3);= // 2<br> =C2=A0 =C2=A0 alias, 1 function definition<br> =C2=A0 =C2=A0 )<br> <br> <br></div></div><div class=3D"im"> I&#39;m not sure I understand the point being illustrated here. I don&#39;t= see<br> how the aliases are relevant?<br> </div></blockquote> <br>
From a compiler perspective, the example above is hell. That was his point.=

<br> In other terms, supporting such a feature add complexity to the compiler, a= nd it should come with a sufficient benefice to make sense to implement.<br=

is hell, but I know nothing about the compiler.</div><div><br></div><div>I = have no idea how the existing bug was implemented, but it needs to be fixed= one way or another.</div> <div>It sounds fairly trivial to me to promote a prototype to a definition = if a definition is found=C2=A0later=C2=A0in the same module.</div></div> --20cf307f3ba28bb1e804ca982774--
Sep 26 2012
prev sibling next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Wednesday, 26 September 2012 at 10:09:14 UTC, deadalnix wrote:
 In other terms, supporting such a feature add complexity to the 
 compiler, and it should come with a sufficient benefice to make 
 sense to implement.

It seems to be just opposite: creating ambiguity between function body and its declaration is a language complexity.
Sep 26 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--bcaec54fb624e2c53104ca9c08e3
Content-Type: text/plain; charset=UTF-8

On 26 September 2012 14:21, Jacob Carlborg <doob me.com> wrote:

 On 2012-09-26 12:19, Manu wrote:

  I can't imagine why the example above is hell, but I know nothing about
 the compiler.

 I have no idea how the existing bug was implemented, but it needs to be
 fixed one way or another.
 It sounds fairly trivial to me to promote a prototype to a definition if
 a definition is found later in the same module.

If the definition is found first, just ignore the prototype?

Indeed. --bcaec54fb624e2c53104ca9c08e3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 26 September 2012 14:21, Jacob Carlborg <span= dir=3D"ltr">&lt;<a href=3D"mailto:doob me.com" target=3D"_blank">doob me.c= om</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg= in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 2012-09-26 12:19, Manu wrote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> I can&#39;t imagine why the example above is hell, but I know nothing about= <br> the compiler.<br> <br> I have no idea how the existing bug was implemented, but it needs to be<br> fixed one way or another.<br> It sounds fairly trivial to me to promote a prototype to a definition if<br=

</blockquote> <br></div> If the definition is found first, just ignore the prototype?</blockquote><d= iv><br></div><div>Indeed.</div></div> --bcaec54fb624e2c53104ca9c08e3--
Sep 26 2012
prev sibling next sibling parent Rainer Schuetze <r.sagitario gmx.de> writes:
On 25.09.2012 13:53, 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,

 I also have numerous more advanced cases of the same problem, and
 becomes even more unsightly when used in structs to emulate dynamic
 linkage to static methods of C++ classes.

 The solution is seemingly trivial; allow function prototypes and
 definitions to exist in the same file, like in C/C++.

I think this should be allowed, aswell as implementing forward declared enums and structs (IIRC the compiler even has some error messages that suggest that it is intended). As a workaround, you could put your prototypes into a struct and generate the declarations for the static linking and the stubs for dynamic linking from their declarations and run your magic on the members of "prototypes": struct prototypes { void fun1(int a, int b); void fun2(int a, int b); } mixin(magic([__traits(allMembers, prototypes)]) That way you don't put the symbols into the same scope as the prototypes, and you will not add new symbols to the same scope that you are iterating over.
Sep 26 2012
prev sibling parent Manu <turkeyman gmail.com> writes:
--20cf303b42f7dc8fbe04caacfca3
Content-Type: text/plain; charset=UTF-8

On 26 September 2012 20:28, Rainer Schuetze <r.sagitario gmx.de> wrote:

 I think this should be allowed, aswell as implementing forward declared
 enums and structs (IIRC the compiler even has some error messages that
 suggest that it is intended).

 As a workaround, you could put your prototypes into a struct and generate
 the declarations for the static linking and the stubs for dynamic linking
 from their declarations and run your magic on the members of "prototypes":

 struct prototypes
 {
         void fun1(int a, int b);
         void fun2(int a, int b);
 }

 mixin(magic([__traits(**allMembers, prototypes)])


 That way you don't put the symbols into the same scope as the prototypes,
 and you will not add new symbols to the same scope that you are iterating
 over.

Good idea! I'll give that a shot. So it seems like there is fairly general consensus on this then, is there a next step? Should I log a bug? (I think I did log one months ago) --20cf303b42f7dc8fbe04caacfca3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 26 September 2012 20:28, Rainer Schuetze <spa= n dir=3D"ltr">&lt;<a href=3D"mailto:r.sagitario gmx.de" target=3D"_blank">r= .sagitario gmx.de</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote= " style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im"><br></div> I think this should be allowed, aswell as implementing forward declared enu= ms and structs (IIRC the compiler even has some error messages that suggest= that it is intended).<br> <br> As a workaround, you could put your prototypes into a struct and generate t= he declarations for the static linking and the stubs for dynamic linking fr= om their declarations and run your magic on the members of &quot;prototypes= &quot;:<br> <br> struct prototypes<br> {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 void fun1(int a, int b);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 void fun2(int a, int b);<br> }<br> <br> mixin(magic([__traits(<u></u>allMembers, prototypes)])<br> <br> <br> That way you don&#39;t put the symbols into the same scope as the prototype= s, and you will not add new symbols to the same scope that you are iteratin= g over.<br> </blockquote></div><br><div>Good idea! I&#39;ll give that a shot.</div><div=
<br></div><div>So it seems like there is fairly general consensus on this =

hs ago)</div> --20cf303b42f7dc8fbe04caacfca3--
Sep 27 2012