Mail Archives: djgpp/2002/06/25/03:31:12
Pedro Izecksohn <izecksohn AT yahoo DOT com> wrote:
> Hi,
> In C++ polymorphism is possible, declaring more than
> once the same function with different parameters, like the
> example bellow:
> void something (int);
> void something (int *);
> Is it possible in C, without using the va_* functions?
Hardly.
> How?
By doing it the same way C++ does it, too --- mostly behind the
scenes. You have to "decorate" or "mangle" the names of the function
to include the types of the arguments it takes. GCC-2.8.1, e.g., will
silently rename the above functions to
something__Fi
and something__FPi
respectively, meaning "function called 'something', taking an int" and
"function called 'something' taking a pointer to an int".
Obviously, that's no fun at all to write by hand. Looked from this
angle C++ is mainly a powerful preprocessor for C. Actually that's
exactly what one of the first few C++ compilers in existence was: a
preprocessor that created (almost) normal C source to be passed on to
the (only slightly extended) C compiler.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -