Thread overview
Re: Function prototype + definition in the same file
Sep 25, 2012
Jonathan M Davis
Sep 25, 2012
deadalnix
Sep 25, 2012
Jonathan M Davis
Sep 25, 2012
deadalnix
September 25, 2012
On Tuesday, September 25, 2012 14:53:17 Manu wrote:
> I really need this. Why is it illegal? Is there chance of having this supported? What are the problems?

I confess that I don't understand why you'd ever need function prototypes, so clearly one (or both) of us is missing something here.

If you you've defined the function, it's there, and that should provide dynamic linkage just fine. The only cases that I can think of where the function _wouldn't_ be defined in spite of actually be in the source file are when it's in a version block or static if which isn't compiled in (in which case, it's not _supposed_ to exist) or if it's a template, in which case, AFAIK, it's _never_ dynamically linkable, but rather it's instantiated in the code which uses the library when it uses that templated function.

So, what am I missing here?

- Jonathan M Davis
September 25, 2012
Le 25/09/2012 18:38, Jonathan M Davis a écrit :
> On Tuesday, September 25, 2012 14:53:17 Manu wrote:
>> I really need this. Why is it illegal? Is there chance of having this
>> supported? What are the problems?
>
> I confess that I don't understand why you'd ever need function prototypes, so
> clearly one (or both) of us is missing something here.
>

It can help IDE for instance. Or help the programmer when looking for references in the source code.
September 25, 2012
On Tuesday, September 25, 2012 19:51:42 deadalnix wrote:
> Le 25/09/2012 18:38, Jonathan M Davis a écrit :
> > On Tuesday, September 25, 2012 14:53:17 Manu wrote:
> >> I really need this. Why is it illegal? Is there chance of having this supported? What are the problems?
> > 
> > I confess that I don't understand why you'd ever need function prototypes, so clearly one (or both) of us is missing something here.
> 
> It can help IDE for instance. Or help the programmer when looking for references in the source code.

I don't understand this. The IDE can see what functions are there. How would having a function prototype affect that? It has to look for the real function regardless, since there's no guarantee that they all have prototypes. The same goes for the programmer. And if it's a matter of knowing what functions in a module are publicly available to use, then that's what generated documentation is for. The only languages that I know of which use prototypes are C and C++, and folks in other languages get by just fine without them. They only exist in C/C++ beacuse of its antiquated compilation model. Sure, they could be useful at times for documentation purposes, but it's code duplication which may or may not be up-to-date with the actual code, especially when the language is advanced enough that it doesn't need a function to be declared earlier in the file than where it's called. And generated documentation or an IDE solves the problem of getting a list of the functions if that's what you want.

Regardless, Manu seems to have issues related to linking, which is a completely separate issue and that's what I don't understand.

- Jonathan M Davis
September 25, 2012
Le 25/09/2012 20:05, Jonathan M Davis a écrit :
> On Tuesday, September 25, 2012 19:51:42 deadalnix wrote:
>> Le 25/09/2012 18:38, Jonathan M Davis a écrit :
>>> On Tuesday, September 25, 2012 14:53:17 Manu wrote:
>>>> I really need this. Why is it illegal? Is there chance of having this
>>>> supported? What are the problems?
>>>
>>> I confess that I don't understand why you'd ever need function prototypes,
>>> so clearly one (or both) of us is missing something here.
>>
>> It can help IDE for instance. Or help the programmer when looking for
>> references in the source code.
>
> I don't understand this. The IDE can see what functions are there. How would
> having a function prototype affect that? It has to look for the real function
> regardless, since there's no guarantee that they all have prototypes. The same
> goes for the programmer. And if it's a matter of knowing what functions in a
> module are publicly available to use, then that's what generated documentation
> is for. The only languages that I know of which use prototypes are C and C++,
> and folks in other languages get by just fine without them. They only exist in
> C/C++ beacuse of its antiquated compilation model. Sure, they could be useful
> at times for documentation purposes, but it's code duplication which may or
> may not be up-to-date with the actual code, especially when the language is
> advanced enough that it doesn't need a function to be declared earlier in the
> file than where it's called. And generated documentation or an IDE solves the
> problem of getting a list of the functions if that's what you want.
>
> Regardless, Manu seems to have issues related to linking, which is a
> completely separate issue and that's what I don't understand.
>
> - Jonathan M Davis

I'm playing devil advocate here, I answered elsewhere that I would be against such modification of the language.