C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
C++ Libraries w/o C Bindings. Can I? Posted by Jakykong on 23 Feb 2007 at 11:04 PM
Hi!
I found an interesting library which I think I can find useful (specifically, nb++). The problem is, the library is implemented as a C++ class, and I program in C.

The library doesn't seem to have any C bindings, and (not that I have a problem with C++) I don't want to spend the time learning another language just to use this library....

Does anyone know if/how it's possible to use a C++ library in C without bindings?
Sincerely,
Jakykong (Jack Mudge)
jack_mudge@hotmail.com
Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by stober on 24 Feb 2007 at 2:56 AM
As you suspected c can not normally call c++ functions, nor can c call java functions, html, pascal, cobol, ada, and a host of functions written in other languages. You might be able to port the library to c, but that might take longer than taking the time to learn c++.
Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by Jakykong on 24 Feb 2007 at 12:55 PM
: As you suspected c can not normally call c++ functions, nor can c call java functions, html, pascal, cobol, ada, and a host of functions written in other languages. You might be able to port the library to c, but that might take longer than taking the time to learn c++.
:

How is it that bindings work, then?

I have the python bindings for ncurses installed on my system, allowing me to use python to write ncurses programs (though ncurses is a C library).

Perhaps a similar thing is possible for using a C++ Library in C?
Sincerely,
Jakykong (Jack Mudge)
jack_mudge@hotmail.com

Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by stober on 25 Feb 2007 at 4:11 PM
: : As you suspected c can not normally call c++ functions, nor can c call java functions, html, pascal, cobol, ada, and a host of functions written in other languages. You might be able to port the library to c, but that might take longer than taking the time to learn c++.
: :
:
: How is it that bindings work, then?
:
: I have the python bindings for ncurses installed on my system, allowing me to use python to write ncurses programs (though ncurses is a C library).
:
: Perhaps a similar thing is possible for using a C++ Library in C?

Notice I said C can't normally call functions written in those other languages because C does not know their calling convention -- it doesn't know how the parameters are pushed and popped on/off the stack, or even if they are pushed/popped. The reverse is not necessarily true -- phthon can call C functions because the phthon language itself included capability to call them. But I'll bet phthon can not call c++ functions without you writing C wappers for the c++ functions.

At least two reasons it is difficult, if not impossible, for other languages to call c++ functions:

(1) name mangling: c++ compilers change the name of the functions to make them unique in the program. This allows c++ programmers to write two or more functions that have the same name but different parameters (called function overloading). This is problematic for other languages because they normally do not know how the c++ functions are named within the library file.

(2) Non-static c++ class functions have hidden parameters (called the this parameter). Other languages don't know how to pass this parameter.
Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by Jakykong on 26 Feb 2007 at 1:52 AM
: : : As you suspected c can not normally call c++ functions, nor can c call java functions, html, pascal, cobol, ada, and a host of functions written in other languages. You might be able to port the library to c, but that might take longer than taking the time to learn c++.
: : :
: :
: : How is it that bindings work, then?
: :
: : I have the python bindings for ncurses installed on my system, allowing me to use python to write ncurses programs (though ncurses is a C library).
: :
: : Perhaps a similar thing is possible for using a C++ Library in C?
:
: Notice I said C can't normally call functions written in those other languages because C does not know their calling convention -- it doesn't know how the parameters are pushed and popped on/off the stack, or even if they are pushed/popped. The reverse is not necessarily true -- phthon can call C functions because the phthon language itself included capability to call them. But I'll bet phthon can not call c++ functions without you writing C wappers for the c++ functions.
:
: At least two reasons it is difficult, if not impossible, for other languages to call c++ functions:
:
: (1) name mangling: c++ compilers change the name of the functions to make them unique in the program. This allows c++ programmers to write two or more functions that have the same name but different parameters (called function overloading). This is problematic for other languages because they normally do not know how the c++ functions are named within the library file.
:
: (2) Non-static c++ class functions have hidden parameters (called the this parameter). Other languages don't know how to pass this parameter.
:


Makes some degree of sense, as frustrating as is.

At this point, I think, then, I'll just pick up a few tutorials and maybe a good book on C++ and go for it...

Thanks for the help!
Sincerely,
Jakykong (Jack Mudge)
jack_mudge@hotmail.com

Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by stober on 26 Feb 2007 at 10:58 AM
:
: At this point, I think, then, I'll just pick up a few tutorials and maybe a good book on C++ and go for it...
:

There's a lot of good information on the net. Read through some of the stickies near the top of the following link

http://www.daniweb.com/techtalkforums/forum8.html

Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by Jakykong on 11 Apr 2007 at 1:16 PM
: :
: : At this point, I think, then, I'll just pick up a few tutorials and maybe a good book on C++ and go for it...
: :
:
: There's a lot of good information on the net. Read through some of the stickies near the top of the following link
:
: http://www.daniweb.com/techtalkforums/forum8.html
:
:

Thanks! That'll help quite a bit.
Sincerely,
Jakykong (Jack Mudge)
jack_mudge@hotmail.com

Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by IDK on 24 Feb 2007 at 5:40 PM
: Hi!
: I found an interesting library which I think I can find useful (specifically, nb++). The problem is, the library is implemented as a C++ class, and I program in C.
:
: The library doesn't seem to have any C bindings, and (not that I have a problem with C++) I don't want to spend the time learning another language just to use this library....
:
: Does anyone know if/how it's possible to use a C++ library in C without bindings?
: Sincerely,
: Jakykong (Jack Mudge)
: jack_mudge@hotmail.com
:

Hmm, couldn't you make a wrapper, and then link it with you're project?:

class{
 func()....
}

func(){
class func
....
}


But that would require some C++ skills...
Report
Re: C++ Libraries w/o C Bindings. Can I? Posted by Jakykong on 24 Feb 2007 at 11:05 PM
: : Hi!
: : I found an interesting library which I think I can find useful (specifically, nb++). The problem is, the library is implemented as a C++ class, and I program in C.
: :
: : The library doesn't seem to have any C bindings, and (not that I have a problem with C++) I don't want to spend the time learning another language just to use this library....
: :
: : Does anyone know if/how it's possible to use a C++ library in C without bindings?
: : Sincerely,
: : Jakykong (Jack Mudge)
: : jack_mudge@hotmail.com
: :
:
: Hmm, couldn't you make a wrapper, and then link it with you're project?:
:
:
: class{
:  func()....
: }
: 
: func(){
: class func
: ....
: }
: 

:
: But that would require some C++ skills...
:


It's something like I was thinking....
The problem would be the C++ skills. I'm not against C++, I was just hoping I wouldn't have to spend the time to learn it :).

It might just be time for me to buy a good book on C++.

"You are coming to a sad realization. Allow or Deny?" "Allow."


Thanks for the help!
Sincerely,
Jakykong (Jack Mudge)
jack_mudge@hotmail.com




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.