🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Jamshid Afshar Wed, 11 Nov 1992 02:14
Can Standard C functions be overloaded?
#653
Author: Jamshid Afshar
Date: Wed, 11 Nov 1992 02:14
19 lines
939 bytes
Can Standard C functions be overloaded?

	#include <string.h>
	int atoi(const String&);   // legal?
	char* s = "123";
	String str = "456";
	int i1 = atoi(s);
	int i2 = atoi(str);

One problem, I believe, is that ANSI C allows functions to be defined
by the implementation as macros, so you might have to do:

	int (atoi)(const String& s);  // now legal?
	String str = "456";
	int i = (atoi)(str);   // annoying

Jamshid Afshar
jamshid@emx.utexas.edu
Re: Can Standard C functions be overloaded
#660
Author: Brian McCauley
Date: Wed, 11 Nov 1992 18:26
12 lines
1036 bytes
In article <83359@ut-emx.uucp>, jamshid@emx.cc.utexas.edu (Jamshid Afshar) writes:
> Can Standard C functions be overloaded?
Yes - according to the book a function may have only one extern "C" defintion
but can also have as many C++ definitions as it wants.
-- 
    \\   ( )  NO BULLSHIT! from BAM (Brian McCauley)
 .  _\\__[oo 
.__/  \\ /\@  E-mail: B.A.McCauley@bham.ac.uk
.  l___\\        Fax: +44 21 625 2175
 # ll  l\\     Snail: 197 Harborne Lane, Birmingham, B29 6SS, UK
###LL  LL\\     ICBM: 52.5N 1.9W
 
Re: Can Standard C functions be overloaded?
#662
Author: Steve Clamage
Date: Wed, 11 Nov 1992 20:01
55 lines
2630 bytes
jamshid@emx.cc.utexas.edu (Jamshid Afshar) writes:


>Can Standard C functions be overloaded?

>	#include <string.h>
>	int atoi(const String&);   // legal?
>	char* s = "123";
>	String str = "456";
>	int i1 = atoi(s);
>	int i2 = atoi(str);

>One problem, I believe, is that ANSI C allows functions to be defined
>by the implementation as macros, so you might have to do:

>	int (atoi)(const String& s);  // now legal?
>	String str = "456";
>	int i = (atoi)(str);   // annoying

The C++ Committee has adopted the following rules (among others)
concerning identifiers in the library section of the Standard:

 - No standard library function may be user-declared, but instead an
   appropriate header must be #include'd.
 - Any function declared in a header must be declared so as to allow
   it to be overloaded by the use of another signature.  (This means
   that a "function" can't be a macro but may be inline.)
 - All identifiers with external linkage are always reserved for use
   as identifiers with extern "C" linkage.
 - Each identifier with file scope is reserved for use as an identifier
   with file scope.
 - Each function signature is reserved for use with both extern "C" and
   extern "C++" linkages as a function signature with file scope in
   the same name space if any of its associated headers is included.

These rules allow an implementation to provide the Standard C functions
as either C or C++ functions with external or file scope (e.g. inline).
They also allow names of Standard C functions to be used as class
member names, or otherwise overloaded.

Of course, current implementations might have tighter restrictions,
since these rules exist only in the Committee Working Paper.

You are probably safe in using a Standard C function name as a C++
function name if you always enclose its name in parens (to avoid clashes
with macro names), and you have a Standard-conforming preprocessing phase.

"Overloading" the Standard C functions is likely to cause odd problems
in general, so for now I would advise against the practice.  (A later
programmer might not appreciate the subtleties and get C macros when
C++ functions were expected.)
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Vice Chair, ANSI C++ Committee, X3J16
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads