home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Standard library functions and macros
- Message-ID: <BzFM01.CD@frumious.uucp>
- Date: Fri, 18 Dec 1992 01:40:48 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <1992Dec07.195917.14566@microsoft.com> <BzCFyM.2r5@frumious.uucp> <1992Dec16.185914.664@microsoft.com>
- Organization: None
- Lines: 60
-
- jimad@microsoft.com (Jim Adcock) writes:
- |Verses it would be nice to be able to port C code to C++ without having
- |to rewrite the whole da*ned thing. My concern is that I am seeing people
- |*trying* to port C to C++ and having a hellish time of it.
-
- Hmmm. My one experience at porting C code (about 80,000 lines of it,
- if I remember correctly) to C++ went quite smoothly. Different cases,
- different experiences.
-
-
- Suppose the C++ standard said that standard library functions must
- have external linkage, and prohibited implementing them as macros.
- Would this change the meaning of any C programs if compiled as C++?
-
- Under this rule, it would still be possible (even easy) for compilers
- to substitute inline code for most calls to certain library
- functions. For example, <strings.h> might contain
-
- size_t strlen(const char* p);
-
- inline size_t __strlen(const char* p) {
- size_t n = 0;
- while (*p++) n++;
- return n;
- }
-
- The only extra knowledge this would require in the compiler is some
- way to know that calls to strlen could be replaced by calls to
- __strlen.
-
- (This is just meant as an easy way for compilers to inline calls.
- In practice, I suspect many compiler writes might embed the
- knowledge of how to generate inline code for some functions
- directly in the compiler, without using tricks such as the above.)
-
-
- |I'm seeing though. Further, the proposed
- |changes take away the ability to selectively decide whether a std library
- |should be implemented in one's code via a function call, or an inline
- |[albeit macro] expansion, without giving programmers an equivalent functionality
-
- Do they?
-
- As Steve Clamage pointed out, you can call the function through a
- function pointer; this will probably cause the compiler to
- generate a true function call.
-
- Going the other way, if the _implementation_ is prohibited from
- making putchar a macro, the _programmer_ should be permitted to
- make putchar a macro. So the programmer who wants to force
- inline code for putchar can simply write the macro. A particular
- implementation might choose to make this easier by providing
- a __putchar macro so the programmer could write
-
- #define putchar(c) __putchar(c)
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-