?
Solved

combain c and c++

Posted on 2003-02-20
8
Medium Priority
?
253 Views
Last Modified: 2010-04-15
how to combain c and c++ please give me a small code
0
Comment
Question by:karudaiyar
7 Comments
 

Author Comment

by:karudaiyar
ID: 7986432
guide me
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 7986606
what do u have to combine ... if u have any ..
whatever u can write in C u can write in C++ also.
so if its just a rewrite then not much of combining needed..
0
 

Accepted Solution

by:
tejfel earned 200 total points
ID: 7986718
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:Gula
ID: 7987873
C doesn't understand C++, so if you have .c file and you write C++ code in it, most of the time it won't compile...
C++ completely understands C, so in your .cpp file you can write as much of C code as you want...you can compile program that is only C in .cpp file

you can have >> << operators to read and write data on one line and printf scanf on another
you can call C function from C++ function

now as akshayxx asked, specify what do you have to combine...


0
 

Expert Comment

by:nagubala
ID: 7988741
Hi,

 Looks like u r trying to call a c function from within a c++ file. In that case u may have to use the following syntax.

extern "C"
{
 C function prototypes. U can list as many as u want.

}


This informs the C++ compiler that these functions are compiled by a c compiler and hence they do not have name mangling done on them. This will make sure that, the linker will have no problems linking the C object files.

Hope this helps.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 8014734
I think youa are new to C++ programming. I have written a small code for you and it think it may help you.

/* C function */
int Sum(int x,int y)
{
     return(x+y);
}

class Arithmetic
{
     int a,b;
public:

     int Add(int x,int y)
     {
            /* C Function used inside a class method */
          return Sum(x,y);
     }
};

/* Main handler to test the program */
void main()
{
     Arithmetic a;
     printf("%d\n",a.Add(12,45));
}
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10010826
Nothing has happened on this question in over 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by tejfel.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question