Re: Function definitions
Re: Function definitions
- Subject: Re: Function definitions
- From: Paul Forgey <email@hidden>
- Date: Sat, 8 Apr 2006 23:29:12 -0700
OK, getting even further OT but if you are going to point this out
it's worth mentioning. In C++ (and therefore objective c++ code
referencing c++ objects) the prototypes are absolutely required
because of function overloading. The compiler needs to deduce which
overload to use given which types can cast to the appropriate
overload, or if the function is exported from a c module.
On Apr 8, 2006, at 6:58 PM, Ondra Cada wrote:
Greg,
On 9.4.2006, at 3:22, Greg Herlihy wrote:
But just because the compiler does not require a function
prototype in this
situation does not mean that the compiler does not need a function
prototype.
Nope, you are looking at it from the wrong perspective. The
compiler does *not* need (neither require) a prototype indeed. This...
4 /tmp> >q.m
int sum(float a, float b) { return a+b; }
5 /tmp> >w.m
#import <Cocoa/Cocoa.h>
int main() { printf("wow! %d\n",sum(5,5)); return 0; }
6 /tmp> cc q.m w.m && ./a.out
wow! 8
7 /tmp>
...is just a plain *programmer's fault*, for the proper code should
have looked this:
21 /tmp> >q.m
int sum(float a, float b) { return a+b; }
22 /tmp> >w.m
#import <Cocoa/Cocoa.h>
int main() { printf("wow! %d\n",sum(5.,5.)); return 0; }
23 /tmp> cc q.m w.m && ./a.out
wow! 10
24 /tmp>
Of course, since it is extremely easy to fall for this kind of
programmer's error, the compiler *allows* (!) you to use
prototypes, and if you do so, it (a) casts for you properly, (b)
checks for your typos (just as I've written previously, that were
the first and second main reasons to use headers).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden