C function overloading?

M

Mabden

Ben Pfaff said:
this?

No. C does not support function overloading.

You could, however, write a wrapper function that calls the normal C
function, but adds new functionality. Many people do this in calling memory
functions, for instance.
 
B

Ben Pfaff

Mabden said:
You could, however, write a wrapper function that calls the normal C
function, but adds new functionality. Many people do this in calling memory
functions, for instance.

Do you know what function overloading is? It is not changing the
behavior of some particular function, i.e. as a wrapper would,
which seems to be your implication.
 
B

Ben Pfaff

jacob navia said:
lcc-win32 is a compiler that supports function overloading.

It is not a C++ compiler

If it supports function overloading then it isn't a C compiler
either.
 
S

Stephen Sprunk

JaSeong Ju said:
I would like to overload a C function. Is there any easy way to do this?

Standard C does not allow true function overloading, such as in C++.

However, you may be able to simulate the effect with macros; examine
<tgmath.h> for ideas how. Note that the method used by <tgmath.h> is
necessarily implementation-dependent, so don't expect your code to be
portable.

S
 
M

Martin Dickopp

Mabden said:
What a nasty question. Of course I do.

Then please explain how a wrapper function and/or adding new
functionality helps to solve the OP's problem.

An ad hominem attack on a regular is reliable way to get into
everybody's killfile. Soon, you might feel very lonely here.

Martin
 
C

Christian Bau

JaSeong Ju said:
I would like to overload a C function. Is there any easy way to do this?

There is no way in C at all.

But what do you actually want to achieve? If you would post "I would
like to overload a C function because..." then maybe you can get help to
achieve what you want to achieve, without overloading a C function.
 
P

Peter Nilsson

Ben Pfaff said:
If it supports function overloading then it isn't a C compiler
either.

Why?! [Yes, I know Jacob's lcc was raised, but speaking more generally...]

Function overloading would require additional constraints on conforming programs using
that extension (e.g. C++ requires function prototypes), but I don't see how support for
function overloading would necessarily preclude implementation conformance.
 
P

Peter Nilsson

JaSeong Ju said:
I would like to overload a C function. Is there any easy way to do this?

Only the old fashioned way...

void my_function_int(int);
void my_function_double(double);

....or by using judicious macros.

Neither is as passe as some might have you think.

As others have said, before you go rushing off to C++, perhaps you might like to explain
if you're trying to do something specific. [And if so, what?]
 
J

jacob navia

Peter Nilsson said:
Why?! [Yes, I know Jacob's lcc was raised, but speaking more generally...]

Function overloading would require additional constraints on conforming programs using
that extension (e.g. C++ requires function prototypes), but I don't see how support for
function overloading would necessarily preclude implementation conformance.

I have taken care (and we discussed here in this group about it) to keep
lcc-win32
100% compatible with the current ANSI standard.

The syntax proposed is:

int overloaded fn(Type1 arg1);

int overloaded fn(Type2 arg1);

When the compiler sees the construction:
fn(Type1) it will call the first one,
fn(Type2) it will call the second one.
else
"Undefined call to overloaded function line 45"

If the compiler sees:
int fn(Type1 arg1);

and LATER
int overloaded fn(Type23);

it will emit an error "function redefinition"

In all cases "overloaded" is NOT a keyword:

int overladed = 1;

will *still work* as expected.
 
C

CBFalconer

Mabden said:
What a nasty question. Of course I do.

It would not appear so.
Do YOU know what a C forum is for? Idiot.

It is not a place for attacks on those more knowledgeable than
you, who happen to point out your ignorance. It will take little
of this to get yourself ignored.
 
J

Joe Wright

Mabden said:
What a nasty question. Of course I do. Do YOU know what a C forum is for?
Idiot.

Alright, impress me. What is meant by function overloading? Even
though C does not support it, please show how to write a wrapper to
do so.

Is 'idiot' a term of endearment to you? If not, it is probably more
applicable to you than it is to Ben Pfaff.
 
M

Mario Charest

JaSeong Ju said:
I would like to overload a C function. Is there any easy way to do this?

Not at the C level I think, but you can do it at the linker level. With
clever ordering of linking library you can replace pretty much any standard
libray call. Of course this is a hack, not portable and depends on linker
behavior. Furthermore; If you try to replace memcpy for example, it may not
work cause some compiler use inline code for memcpy and alike. Using this
solution is risky.
 
C

Christian Bau

"Peter Nilsson said:
Ben Pfaff said:
If it supports function overloading then it isn't a C compiler
either.

Why?! [Yes, I know Jacob's lcc was raised, but speaking more generally...]

Function overloading would require additional constraints on conforming
programs using
that extension (e.g. C++ requires function prototypes), but I don't see how
support for
function overloading would necessarily preclude implementation conformance.

If I understand it correctly, the compiler would have to tell you the
first time it encounters something that is not pure Standard C, and then
it can go on doing whatever it likes. So if you write code by mistake
that is not Standard C but would be legal if function overloading were
part of C, then the compiler MUST tell you. But it can allow function
overloading after that.
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top