It is currently Tue, 30 Nov 2021 18:39:37 GMT

Author Message
 why distinguish C++ function from C function?
why distinguish C++ function from C function?


 Sat, 10 Jan 2004 21:14:19 GMT   
 why distinguish C++ function from C function?

because c and c++ are different languages.  a c compiler won't compile
c++ code.

"... What with you being his parents and all, I think that you could
be trusted not to shaft him."  -- Robert Chang,

John Gordon                     

 Sat, 10 Jan 2004 21:16:49 GMT   
 why distinguish C++ function from C function?
C++ functions are subject to overloading.  C functions are
not.  As a result, the functions are handled differently in the
loader and the symbol table.  If a C++ program knows it is
dealing with a C function (using the key 'extern "C"'), it then
knows how to access the function.  The reverse is not true.
C does not have anything built-in for dealing with C++

Fletcher Glenn
to reply remove NOSPAM from my reply address

 Sun, 11 Jan 2004 00:13:41 GMT   
 why distinguish C++ function from C function?

More concretely, since C and C++ functions have differing linkage, a
compiler could actually call C and C++ functions in different ways; for
example, pushing arguments on the stack in reverse order, etc.

 Erik Max Francis / /
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Here day fights with night.
\__/ (the last words of Victor Hugo)
    Maths reference /
 A mathematics reference.

 Sun, 11 Jan 2004 03:03:44 GMT   
 why distinguish C++ function from C function?
On 24 Jul 2001 06:14:19 -0700,
   <> wrote:

I think that the fundamental reason is to allow function overloading. In C,
if you define a function with one set of parameters, then the compiler
will {*filter*}if you redefine it with another set of parameters (assuming
both functions are in the same scope).

The real cause for this limitation is the linker. The linker doesn't
care much about the parameters of functions. It's up to the caller and
callee to match the parameters sent and read (and in the case of ...
parameters, the callee has to do this dynamically).

To overcome this, C++ mangles the function names. The mangling is
compiler-dependent, but it typically transforms a function like
func(int, int, char&) to __[ID][class]func[encoded parameters]. That
means that the dumb linker gets to see unique function names for
all functions defined, even overloaded ones.

A bientot
Dr. Paul Floyd       Silvaco Grenoble Research Centre
55, rue Blaise Pascal, ZIRST II, 38330, Montbonnot St. Martin, France      Tel: +33 (0)4 56 38 10 34

 Sun, 11 Jan 2004 16:39:07 GMT   
   [ 5 post ] 

Similar Threads

1. C functions calling C++ functions on Solaris

2. C++ class member function as a thread function.

3. function, function...who's got the function?

4. Function pointer to member functions

5. Main function calling another main function

6. function calls versus function pointers ?

7. passing variable number arguments from function to function

8. cloning functions/dynamic functions

9. About function that returns function pointer

10. Tree of Functions calling Functions etc.

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software