Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling a C program inside of a C++ program?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can you compile and run a C program inside of Visual studio?

Also can I call a function in a C program into a C++ file.
 
Yeah sure,all C++ compilers support the C syntax.

You can call the functions written in the C program from the C++ code, just include the .c file into Ur project.
If you have a main() function defined in Ur C program you mght have problems, the solution will be to either remove the main() routine from the C program or just yank out the functions you require in a seprate C file and include it in Ur project.

cheers

amit
crazy_indian@lycos.com

to bug is human to debug devine
 
Thanx for the info ..... but there are a few subtleties ..... It seems like you need to change the name from *.c to *.cpp. I created a simple C program without any code in the main and tried to call it from a C++ ..... kept getting a "unterminated string " and all sorts of weird errors. Change the name to CPP and walla .... it worked.

Is that a speacial case or is it always true that you need the change the file extension to cpp?
 
I missed out on the extensions. Yeah you do have to change the names of all the .c files to .cpp for it to work in VC++.

-cheers



amit
crazy_indian@lycos.com

to bug is human to debug devine
 
I have just tried to call a c-function from a c++ function, and found it works ok.

Only your c-module function mus be prototyped between the braces :

extern "C" {
/* C-prototypes goes here :*/

void c_func(void);
}


/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top