Groovy hepcat jacob navia was jivin' on Thu, 09 Jun 2005 22:06:31
+0200 in comp.lang.c.
Re: overloaded functions in C's a cool scene! Dig it!
You misunderstand overloaded functions.
I don't think he does. I think he understands better than you do
that overloaded functions break standard compliance.
suppose:
int overloaded fn(Mytype *arg);
int overloaded fn(MyOtherType *arg);
overloaded is in user name space. Hence you break standard
compliance.
They are *not* the same object of course. They are TWO
different functions, that's the point!
----------------------------------------------------------------------
6.2.1 Scopes of identifiers
....
2 ... Different entities designated by the same identifier either have
different scopes, or are in different name spaces. ...
----------------------------------------------------------------------
This means that an identifier cannot designate multiple entities
within the same scope and name space. Thus, overloading is effectively
disallowed.
The user has the facility of calling those two objects
with the same name with different argument signatures.
Yes, we know what overloading is. But it is not allowed in C.
Someone pointed out that you could emit a diagnostic and compile it.
If that's what you do then that's fine. Then you can claim your
compiler is a standard conforming C compiler. But if it does not emit
a diagnostic when encountering overloaded functions, then it is not a
C compiler.
To stay within the standard, the overloaded function sqrt
refers to 3 different functions:
sqrt is not an overloaded function. It is, if tgmath.h is included,
a macro that uses some method to determine which of several functions
to call. We usually call this "compiler magic" because we, the users,
are not concerned with how this works. For all we know and care it
could be magic. (It doesn't require "compiler magic" to include
function overloading either. This could probably be implemented using
__typeof - which *is* allowed as an extention as it doesn't break
standard conformance - to determine which function to call. Or some
other incantations may be possible to achieve the desired ends. In any
case, the users are not supposed to know or care how. That is an
implementation detail.)
sqrtl(long double), sqrt(double) and sqrt(float).
This overloading doesn't mean that there is ONE sqrt function
but three of course.
No. It doesn't mean any such thing. It means there is one sqrt macro
which calls one of several functions, depending on the type of its
argument.
My implementation will not accept:
int overloaded fn(Mytype *arg) {... }
int overloaded fn(Mytype *arg) {... }
because THAT would be a redefinition of the same object, as the
standard specifies!
That is not at issue.
--
Dig the even newer still, yet more improved, sig!
http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?