A language that can seamlessly interop with C++? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I like to try out many different programming languages but I can never really use many of them in real projects because all important libraries that I need are written in C++.
Usually I have to write a C-Interface which can be pretty time consuming, so I am wondering does a programming language exist that can seamlessly call any C++ code?

Many functions in C++ are defined in header files, and expected to be compiled into every application using them. It occasionally happens for C too, but for C++ it is far more common, particularly as class members for templated classes cannot be made available in advance for every potential template instantiation: there are infinitely many.
If compatibility with C++ requires a complete C++ parser and compiler, you've not really got a different language, you've got C++ with extensions. Even if one of those extensions is to make parts of the code look nothing like C++, it adds massive complexity for little benefit.
If you don't need complete and seamless compatibility with C++, then limited compatibility is available in some languages. There is D's Interfacing to C++, describing what works, what doesn't, and why not.

There is an experimental language that can do so, but there's only one developer (myself) and it's in such an early stage of development that it's not useful right now.
Here's a simple sample program:
Main() {
cpp("iostream").std.cout << "Hello, World!";
}
FTR, compiling this sample requires ADL, OR, template instantiation, ABI compliance, parsing the C++ header in question, and lots of fun stuff.

No language can seamlessly interop with C++. C interfaces are a good idea. It's important not to export all / many functions from the module, because it's time consuming as you noticed. Focus on solving one problem at time and export the function solving this problem to C.
On the other hand, if you really need to expose many functions or even classes to other language, you can use SWIG. Read its documentation and you'll notice how many problems it needs to deal with while creating the wrapping code. That's because any two languages are different and you can't change that. The solution to this problem is to use the greatest common interface of two languages - C.

The only solution that meets your requirements is V8 / Javascript from Google.
Is the only implementation of a scripting language written in C++ that I know of, plus the API themselves are exposed via C++ too .
The downside is that is not a simple project, is not exactly available on any platform, it's being developed according to the Google needs and there are no guidelines or standards, for example C++ is being versioned by ISO documents that are released each time a new milestone is out and each one of them defines the standard, V8 is more like an ongoing project with some big voids, especially in terms of invariances , standardization and concurrency.
For example there is nothing that keeps Google from changing the entire set of APIs from one version to the other, and unless you are counting on a really big team, I doubt that you can keep up with that.

Related

Why is there a networking library proposal for C++14/17? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Even though TCP/UDP/IP are commonly used protocols, I do not understand why they want it to be part of the ISO C++ Standard. These have nothing to do with the core of the language. Data structures are universally required tools hence STL makes sense but these protocols are too specific IMO.
There has been a long-standing sentiment that the C++ library's tiny focus area is something bad that's holding the language back. Most "modern" languages come with large framework libraries which include networking, graphics and JSON. By contrast, if you want to do any of these in C++, you a) don't get anything by default, and b) are overwhelmed with a choice of third-party libraries which you are usually unable to appraise properly and select from.
This is how that side of the opinion goes.
Of course there are other people who think that that's just the way it should be. Nonetheless, standardization is hard work, and whereas languages like Java and C# and Go have large companies behind them that can put energy into developing a huge library, C++ doesn't have that kind of manpower, and most people who spend time on C++ standardization are more interested in core aspects of programming: data structures, concurrency, language evolution (concepts, ranges, modules...).
So it isn't so much that people are generally opposed to a larger library, but it's not a priority for many. But if good ideas come around, they have a good chance for being considered. And large library components like networking won't be going into the standard library anyway, but rather into a free-standing Technical Specification, which is a way to see whether the idea is useful, popular and correct. Only if a TS gets widely used and receives lots of positive feedback will there be a possible future effort to include it into the IS.
(You may have noticed similar efforts to create Technical Specifications for file systems and for graphics.)
C++ 11 includes Threading in Standard. Now programmers need not to write PThread in Linux and Windows Threads in Windows, separably. Same can happen if Networking library gets Standardized.

Writing pure code without using third-party header files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
As try to learn C/C++, I'm always finding it frustrating that I need to use the header files. It makes it seem like it's not my code, but I am using some other person's code instead. I simply want it to be pure, and be written by myself without using the header files.
I know for certain that C/C++ includes libraries that can give the developer some functions in order to for example create a vector. The Boost library are similar to that, but again, I want to write my own code, and maybe create my own library for my work.
But is this possible? If I wrote my own header files for C/C++ that almost acted like the iostream.h file for example, only that I've made it my own, and optimized it, will it be beneficial for my applications/projects, or should I just use the standard library that is included with the programming languages?
My answer comes, at least partially, in the form of a rhetorical question:
Are you also going to write your own compiler?
You're always using something that someone else wrote, and for general-purpose use this is a very, very good thing. Why? Because they are the experts in their field, because they are multiple people, and because their code has gone through decades of rigorous peer review, thorough testing by millions upon millions of people, and many iterations of improved versions.
Shying away from that as an instinct is one thing, but refusing to use standard headers due to it is quite another, especially when you draw the line so arbitrarily†.
In short, there is a damned good reason why the C++ standard defines the standard library and why your compiler vendor ships an implementation of it. My strong recommendation is that you work to that principle.
† …which is why mine is not a "slippery slope" argument!
Off course you should use the standard library. The only reasons not do so are:
The class you want does not exist.
You are a pro C++ programmer and something about its implementation really annoys you.
You as a beginner want to learn something by trying to build your own simple data storage types (like for instance any vector type )
Your thoughts about "all should be made by yourself" are not that uncommon, but once you've implemented one of the standard types and have spent hours on it while your actual project hasn't progressed one line and when your new "own" type still misses half of the functionality - Then you'll realize that using an existing library (especially the standard library or well known others like boost) might actually be a clever thing.
It makes it seem like it's not my code, but I am using some other person's code instead.
How would you write the <fstream> library? Opening files is not something that can be done in the pure C++ language. A library that provides that capability is needed. At base, opening files has to be done by the operating system and the OS exposes that to your code. The OS itself has to deal with other software that enables it to do these things.
Or what about this: Addition doesn't happen by magic, so somebody had to spell out exactly how to do it for your program to be able to do a + b. Does writing a + b make you feel like you're using other people's code, the code which describes how the add instruction is implemented on the CPU?
No single piece of software is going to do everything. Every piece of software will have to interact with other components, and virtually always some of those other components will be the results of someone else's work. You should just get used to the idea that your software has its own area of responsibility and it will rely on others to handle other things.
Re-inventing the wheel is a bad idea. Especially if that wheel has been designed and built by people smarter and more knowledgeable by than you and is known to everyone else who is trying to build cars (program C++).
Use the headers; don't be daft.
By the time one re-implements most standard routines, one might as well make a new language. That why we has a wide selection of languages from which to choose. Folks have dreamed-up a better idea. Re-inventing the wheel is good - we don't drive on chariot tires much these days.
C and C++ may not be the greatest, but with 40 years of history, they do have holding power (and lots of baggage). So if you are going to program in a language - use its resources, with its strengths and weaknesses. Chances are far greater, your solution, will not be better than the existing libraries improved 1,000s of others.
But who knows - you code may be better.

What Apple API's have C++ accessibility and not just Objective-C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking for a way to know what Apple API's I can use with C++ and not just Objective-C. iOS 7.
Is there a resource or way I would know this when I am planning out my apps functionality?
I know I will need some Objective-C at least. I can handle that. I am just not as comfortable with Objective-C at this point in time but I still have app ideas.
I am just not as comfortable with Objective-C at this point in time but I still have app ideas.
Objective-C is a very simple language. You could specify all of the things it adds to plain C on a couple of pages. The syntax looks odd at first, but that disappears quickly. The hard stuff is all down to it being a superset of C, which won't be a problem for you if you're used to C++.
The iOS APIs, on the other hand, are not simple at all. There are loads of them and they take time to learn.
Learning the language is easy compared to learning the APIs. Learning the APIs is easier if you use them in the native language. So my advice would be to do that. Or, possibly use a C++ framework that wraps them up in C++ classes. Using the native APIs in C++ (to the extent that it's possible) isn't a good idea.
Objective-C and C++ do OOP very, very differently. Objective-C does things closer to real message sending, as opposed to directly calling a function. That allows for a level of dynamism that makes C++'s head spin, and means that C++ objects and Objective-C objects are incompatible in a bunch of ways.
If you're intent on trying to use C++ to manipulate Cocoa objects, Objective-C++ was (is?) an attempt to do with C++ what Objective-C does with C. I haven't heard much good about it, though.
Other than that, you will need to become familiar with objc_msgSend (the function Objective-C uses to actually send a message to an object). Cause you'll be using it a lot.
Well trying to keep the answer simple. There is no conflict between C++ and Objective-C.
You can use both for your development purpose and even in a same project/class.
Unfortunately, Apple does not expose any direct application level API in C++, rather it sticks to Objective-C for that purpose. However, Apple's foundation APIs are still based on pure C and thus you can create your own wrapper in C++, to call those foundation frameworks to build your own application framework. But that would certainly incur a huge overhead on the development process.
I recommend you to stick to Objective-C based AppKit/UIKit for UI and front-end development whereas you can still use pure C/C++ for your business objects. For example, if you are developing a game, you can create C/C++ classes for implementing your processing/rendering logic and implement only the screen output logic in Objective-C. You can safely use C/C++ classes/methods inside your Objective-C class. So you dont have to worry about the interoperability.

Standard library implmentation source that hasn't had names uglified [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Reading C++ source code can obviously be a good way to learn and is just plain interesting when its a feature you know very little about. As far as standard library source goes this is difficult due to the uglifying of names.
Is the uglifying done through some sort of post-processing of the source code before it's inclusion in the standard library? If so, what happens to the original source code? Are there any repositories of non-uglified C++ Standard Library source code?
I'm interesting in looking at C++11 and soon C++14 features in particular.
I can't imagine maintaining code in this form would be very fun....
EDIT:
There's a proposal to do away with this process here.
When learning from standard library implementations, please first of all note that the standard library has to obey certain harsh constraints which don't apply to code written by normal users. Also, some of the operations done by standard C++ libraries are somewhat esoteric and I would be worried if they were ever used by normal user's code (if you have a low-level library team in you company, they might do some similar stuff, though). In particular on constraint standard libraries need to obey is that none of the names used conflicts with any names used anywhere by users. Since users could define funny macros, the standard library needs to use names reserved for the standard library in user-visible contexts, e.g., the header files:
names used in the standard C++ library for classes, functions, enumerations, etc. or tmeplates thereof (when applicable) are reserved.
all names starting with an underscore followed by a capital letter or names containing two consecutive undersscores are reserved in all contexts.
there are a couple of other reserved names which are, however, typically not used in the headers because they are mostly not reserved in the context of macro names.
The things you specifically do not want to copy from the standard C++ library is the naming of the include guards: these typically start with one or two underscores and are all uppercase characters. Users are not allowed to use any of these identifiers unless they are specifically allowed to use them (e.g. you can use __FILE__ and __LINE__ but you are not allowed to, e.g., write _FOOBAR anywhere in your program where it could be expanded by a macro (that is, I think you can write "_FOOBAR").
To answer your actual question: all standard C++ library implementations I'm aware of (libstdc++, libc++, Dinkumware, RougeWave, and my own) are written using "uglified" names and there is no program converting them into this form. Basically, any program would have to deal with lots of exceptions which isn't quite feasible. I think, standard C++ library implementers just get used to the funny names. For my implementation I had made an effort to name everything with a common prefix so that the uglification could be undone using a simple sed script but I haven't followed that pattern everywhere.

C++ for the C# Programmer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I have a good understanding of OO from java and C# and I'm lucky in my engineering courses to have been exposed to the evils of both assembler and C (pointers are my playground :D ).
However, I've tried looking into C++ and the thing that gets me is the library code. There are so many nice examples of how to perform the bread and butter tasks in java and C#, but I've not been able to find a good explanation of how to do these things in C++.
I'd love to expand my knowledge into C++ to add to my skillset but I've not had a chance to be exposed to people and communities that are keen on these things.
Could anyone here recommend some good open source projects or tutorials which are useful. Bonus marks if they involve coming from java or C# into this environment.
I'd suggest that you work your way through the excellent Andrew Koenig and Barbara Moo book "Accelerated C++" (sanitised Amazon link). This book teaches you C++ rather than assume that you know C and then look at the C++ bits bolted on.
In fact, you dive in and are using STL containers in the early chapters.
Highly recommended.
As well as the other answers here, I think you should take a look at the QT toolkit. Not only does it have GUI widgets, it also has libraries to work with things like databases, multithreading and sockets.
A combination of BOOST and QT, IMHO, provides you with the tools to address in C++ any problem you might be faced with.
I don't have any such resources for you, unfortunately, as I took the long way of slowly discovering things piece by piece.
I do have a caveat for you, though: keep in mind that in the C++ world, the standard library has been very slow at providing useful services. Basically, you'll find a few algorithms, data structures, a few string-related classes and some basic I/O-related ones. Unlike Java or .Net, there is not an extended library of classes for all kinds of purposes (networking, file system services, cryptography, concurrency, etc) - the closest to that is probably Boost, which looks and feels like an extension to the standard library, but which is still external (although some parts of it are leaking back to the standard library).
It's worth bearing in mind that C++ is primarily a systems programming language. Thus its main emphasis is not on performing bread & butter tasks but on writing the tools that are used to perform those tasks. For example, rather than supplying database access libraries out of the box, C++ is intended to be used for writing the database engine itself.
Assuming you already have some knowledge of the C++ syntax, and have good Object Oriented experience I'd go for Effective c++ series.
It's a collection of "tips and tricks" explaining how c++ works under the hood. Which are the common misunderstandings from people coming from other languages and why c++ works this way.
It depends what platform you are programming on. C++ itself doesn't have the same sort of library that Java or C# have. That sort of functionality is traditionally supplied by the operating system. I suggest you learn C++ from a book (I like C++ Primer by Lippman but it may be a bit slow as its aimed at beginners) and then head to MSDN if you are programming on Windows. There are APIs for networking, XML parsing, encryption, just about everything you need. They are just tied to the OS instead of the language itself.
I don't know the equivalent resources for Linux or the Mac but I'm sure someone can supply them.