L
lordkain
is it possible to do some kind of function overloading in c? and that
the return type is different
the return type is different
is it possible to do some kind of function overloading in c? and that
the return type is different
Richard said:Incidentally, you hint that you wish to be able to distinguish between
functions of the same name purely by virtue of their having different
return types. Even C++ (which *does* support function overloading) cannot
do this.
Chris Dollin said:There are languages which do. I /think/ Ada is one of them. But this
is a fuzzy memory from -- ye gods and little finches -- more than 20
years ago.
is it possible to do some kind of function overloading in c? and that
the return type is different
KISHORE said:Since If we observe The limitations of c,and list out them we can
conclude that function overloading cannot be done in c language.thats
why there r seperate functions for different types in <math.h> to
clarify ur doubt open turboc editor and open math.h header file and
gothrough the function declerations.u can know the answer.
Harald said:Richard Heathfield wrote:> Incidentally, you hint that you wish to be
able to distinguish between > functions of the same name purely by
virtue of their having different > return types. Even C++ (which *does*
support function overloading) cannot > do this.<OT>Yes, it can, in
limited cases. An example (of poor C++-style):#include
<stdio.h>namespace A { void foo() { puts("void foo()"); }}namespace B
{ int foo() { puts("int foo()"); return 0; }}using A::foo;using
B::foo;int main() { ((void(*)()) foo)(); ((int (*)()) foo)();}</OT>
<OT>Yes, it can,
in limited cases. An example (of poor C++-style):
#include <stdio.h>
namespace A { void foo(){puts("void foo()");}}
namespace B { int foo(){puts("int foo()"); return 0;}}
using A::foo;using B::foo;
int main() {((void(*)()) foo)(); ((int (*)()) foo)();}
</OT>
is it possible to do some kind of function overloading in c? and that
the return type is different
CBFalconer said:A shining example of why not to use the faulty google interface to
usenet.
My implementation does something similar to this:
int foo_char(char x);
int foo_int(int x);
#define foo(x) { if (sizeof(x)==sizeof(char)) foo_char(x); else
foo_int(x); }
Keith said:Since I've never seen this particular problem in a Google post, it's
not clear that Google is at fault.
Richard Heathfield schreef:
I may be mistaken here, but I have a hunch that you have not asked the
question you perhaps ought to be asking. It seems to me that there is some
task (call it X) that you need to achieve, and you've thought about it, and
decided that function overloading would be a way to achieve that task, and
so you're asking about function overloading, whereas you may find it more
productive to ask about ways in which X itself, whatever it may be, can be
achieved.
or look at the subject [xml to function call] in the google newsgroup.
Tor Rustad said:Stephen Sprunk skrev:
You should consider using the macro
#define foo(x) ((sizeof((x))==sizeof(char) ? (foo_char((x))) :
(foo_int)((x)))
instead. However, this will not work in cases like
foo( foo(x) )
so I guess most C99 implementations use compiler magic
#define foo(x) __foo_generic((x), foo_char, foo_int)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.