?
Solved

combain c and c++

Posted on 2003-02-20
8
Medium Priority
?
250 Views
Last Modified: 2010-04-15
how to combain c and c++ please give me a small code
0
Comment
Question by:karudaiyar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Technology Partners: 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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

762 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