By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 2,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

Converting C functions into c++ functions...

P: 84
Hi everyone. I have used some functions like gotoxy() for ages, they would work perfectly under Turbo C and were easy to use... Had no problems, nothing! But since i am using Dev c++ 4.9.9.2, those functions are not available. I am currently needing them for my programs (which are made under dev c++) and can't get to make it work.

I have tried to make an executable by using TurboC which (having been given command-line parameters) would go to the position in console specified. Then, i made a program in dev-c++ in which you just wrote 2 numbers and the program would run the c executable with the parameters given... A real hard work (had to make the numbers into char array and join loads of char arrays)... But when i got to the end and compiled, the program crashed, a windows error message would appear and say that the program had to be closed, but what surprises me is that it crashes after finishing that function (all the code for the gotoxy is in a function). If i turn the line into a comment it does not crash or anything. I do not use any global variables so i'm really confused.

So after this hard work i want to ask you whether you know about any library or anything able to solve this kind of problems, so that i can use c functions??


Any help would be very appreciated.
Kind Regards,

John Paul (or "Juan Pablo" as my friends say...)
Jun 17 '07 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
So after this hard work i want to ask you whether you know about any library or anything able to solve this kind of problems, so that i can use c functions??
This sounds like a C++ mangling issue. C++, becuse of function overloading, has to convert function name plus their argument types into a unique name for the linker. To do this the C++ compilers encode the function name plus the arguments into a cryptic name that varies by compiler.

You say this worked in C.

So I would make a C++ header file that tells the complier to not mangle th function name:

Expand|Select|Wrap|Line Numbers
  1. extern "C" gotoxy();
  2.  
Build using this in your C++ heade and add the C library to your link.

The extern "C" tells the compiler that the function name comes from C and must be used by the C name only.
Jun 17 '07 #2

P: 84
This sounds like a C++ mangling issue. C++, becuse of function overloading, has to convert function name plus their argument types into a unique name for the linker. To do this the C++ compilers encode the function name plus the arguments into a cryptic name that varies by compiler.

You say this worked in C.

So I would make a C++ header file that tells the complier to not mangle th function name:

Expand|Select|Wrap|Line Numbers
  1. extern "C" gotoxy();
  2.  
Build using this in your C++ heade and add the C library to your link.

The extern "C" tells the compiler that the function name comes from C and must be used by the C name only.
Sounds like it will work
Jun 19 '07 #3

gpraghuram
Expert 100+
P: 1,275
Hi,
in the header file u use add this definition
Expand|Select|Wrap|Line Numbers
  1. #ifdef _cplusplus
  2. extern "C" {
  3. #endif
  4.  
  5. /*your declaratons */
  6.  
  7.  
  8. #ifdef _cplusplus
  9. }
  10. #endif
  11.  
Check the #ifdef name (i am not sure whether it is __cplusplus or _cplusplus

Raghuram
Jun 20 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.