C (241/257)

From:
Date:26 Feb 2001 at 14:38:44
Subject:Re: Link together C and C++

Hi Vassili,

--- Vassili Smirnov <backa@compic.ee> a �crit : > Hi!
>
> I got troubles when mixing C++ and C source,
> for example:
>
>
> /*--------------------------*/
> /*--------- test.h ---------*/
> /*--------------------------*/
> #ifndef TEST_H
> #define TEST_H
>
> void myFunc(void);
>
> #endif
>
> /*--------------------------*/
> /*-------- test.cpp --------*/
> /*--------------------------*/
> #include <stdio.h>
> #include "test.h"
>
> void myFunc(void)
> {
> printf("Just a test.\n");
> }
>
> /*--------------------------*/
> /*-------- testmain.c ------*/
> /*--------------------------*/
> #include "test.h"
>
> void main (void)
> {
> myFunc();
> }
>
>
> When I link objects, SAS doesn't find define symbol
> for _myFunc.

It's normal because a C++ compiler generate functions
with some informations like parameters, return type,
... into the name of the function. It's for
overloading purpose.

> What is going? When I rename "test.cpp" to "test.c"
> , compile
> and link, all is OK!
>
> I need classes in myFunc, and I can't use C++ in
> main()!

No, the solution is to have a C++ testmain (so you
have only to remove testmain.c into testmain.cxx, or
.cpp).

As a conclusion :

- C++ may call C function
- it's difficult to call C++ from C.

Bye

Laurent

=====
The misspelling master is on the Web.
_________
/ /(
/ Dico / / 100 % Dictionnary Free !
/________/ /
(#######( /

Quoi, des fautes d'orthographe! Pas possible ;-D.

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/