Feature request: function prototypes

Jesse Phillips jessekphillips at gmail.com
Fri Feb 8 08:24:43 PST 2008


On Fri, 08 Feb 2008 12:44:04 -0200, Ary Borenszweig wrote:

> Christopher Wright wrote:
>> Robert Fraser wrote:
>>> This may seem like a pretty stupid request, but since I use a lot of
>>> version() statements in my code; it'd be really cool to have something
>>> like function signatures at the top of my file. When I declare my
>>> versioned functions, I'd love to be able to have them checked against
>>> prototypes declared above their use, as a first line of defense (so I
>>> don't need to r-test it on different OSes and libraries if I make an
>>> obvious change to one of the signatures or something).
>> 
>> Have a unittest? To satisfy your purposes, it just needs to call each
>> function, even with invalid input. Then if everything compiles with
>> -unittest, you're golden, even if that crashes.
>> 
>> Satisfies your requirements, anyway, and in any situation, you'd be
>> duplicating the signature three times.
> 
> But unittests are run with specific version flags.
> 
> I think he means something like this:
> 
> ---
> prototype {
>    int someFunc(float, bool);
> }
> 
> version(one) {
>    int someFunc(float f, bool b) {
>      // ...
>    }
> } else {
>    int someFunc(float f, bool b) {
>      // ...
>    }
> }
> ---
> 
> Now, if you change the signature of someFunc inside of version(one)
> you'll get a compiler error, because the prototype "int someFunc(float,
> bool)" would not be found if version is "one". Alternatively, if you
> change the prototype inside the "prototype { }", you'll get two compiler
> errors: in "one" the prototype doesn't exist, neither in the "else".
> That way you can maintain synchronized the two version blocks.
> 
> The problem is, how to implement this? The compiler would need to check
> all possible combinations of versions, debugs, static ifs, etc.
> 
> By the way, this will also allow tools to provide good refactoring
> support.

If that is the case I would much rather have the prototype leave off the 
parameter-list and only require all declarations to be the same.



More information about the Digitalmars-d mailing list