In general, how portable is C++ compared to C? For example, if a new device gets released (think back to the days when the iphone or droids were first released) is it just as likely to have C++ support as it is C support? Do embedded systems usually support C++ if they support C? I know C has compiler support for most devices under the sun, but I hear less about C++'s support, which is why I'm asking.
Thanks!
Portability of C++ Compared to C
Nowadays C++ is more or less just as portable as C in the sense that pretty much every platform with a C compiler has a C++ compiler. However, not every C++ platform supports the full range of C++ features. Some may not have exceptions or have such bad exceptions that they might as well not have exception support, or may have bad template support, etc. That's not even getting into C++11. Then again, not every platform has full C99 support either.
iPhone never supported C, it only support Obj-C (Apple way of beeing "different"). Android and almost every other embedded platform ever done is using a Unix base, and it can build using GCC. GCC is supporting C++ perfectly since years so it shouldn't be a problem, just be sure you don't have a OS older than 20+ years.
As SiCrane said however, supported features could be different on some platform. No really a problem for future products, but mostly for older.
As SiCrane said however, supported features could be different on some platform. No really a problem for future products, but mostly for older.
iPhone never supported C, it only support Obj-C (Apple way of beeing "different").
That's wrong. Xcode and the iOS SDKs sport both GCC and Clang. You're free to use C, C++ or Objective-C. Objective-C is just the language Apple choose to implement various frameworks they provide (UIKit, Foundation, GLKit, etc.). Yes, you'll most likely have to use Objective-C somewhere in your codebase, but you can minimize that to only where you need it and use C for the rest of your program if that's what you want.
This question in such general form doesn't make much sense.
C or C++ source code is compiled into something else. It's then linked. Finally, it's executed.
GCC family of compilers, as well as Intel, clang, even MVS all take care of first part. They emit generated native code. Depending on compiler, this code may be limited in what it targets. x86/64 support is fairly decent to a degree, so are common ARM architectures. But having a blob of assembly isn't all that useful.
We then need to link this code with OS or include rudimentary OS replacement (majority of systems do not have an OS). Code that does this using standard library will be portable to systems which provide compatible standard library. For OS-specific functionality, we need platform libraries to link.
Finally, it comes to running it. Run-time platform may very well be, and often is different from development platform. Running such code may not be as straightforward as simply navigating the file system and running an executable.
C or C++ code do not have notion of portability since they don't define any of the above. Both syntaxes are only relevant to compiler that generates native (or even some intermediate) code. The linker and run-time environment simply aren't part of this equation.
From engineering perspective - a project is portable precisely to the platforms it has been ported to. Any other assumption is a simple fallacy. Only exception are certified runtimes, such as Java.
C or C++ source code is compiled into something else. It's then linked. Finally, it's executed.
GCC family of compilers, as well as Intel, clang, even MVS all take care of first part. They emit generated native code. Depending on compiler, this code may be limited in what it targets. x86/64 support is fairly decent to a degree, so are common ARM architectures. But having a blob of assembly isn't all that useful.
We then need to link this code with OS or include rudimentary OS replacement (majority of systems do not have an OS). Code that does this using standard library will be portable to systems which provide compatible standard library. For OS-specific functionality, we need platform libraries to link.
Finally, it comes to running it. Run-time platform may very well be, and often is different from development platform. Running such code may not be as straightforward as simply navigating the file system and running an executable.
C or C++ code do not have notion of portability since they don't define any of the above. Both syntaxes are only relevant to compiler that generates native (or even some intermediate) code. The linker and run-time environment simply aren't part of this equation.
From engineering perspective - a project is portable precisely to the platforms it has been ported to. Any other assumption is a simple fallacy. Only exception are certified runtimes, such as Java.
This question in such general form doesn't make much sense.Yes it does, you just chose to interpret it differently so you could go off on an arrogant rant.
When a new platform comes out, you're usually stuck with the toolchain that's given to you in the official SDK for that platform. If you're a licensed developer for that platform, you may not even have a (legal) choice about using a 3rd party SDK vs the official SDK.
If the official SDK has a buggy C/C++ compiler, or a buggy Java VM, or is missing a C# compiler -- then those are your limitations when it comes to portability.
In an ideal world, every C++ compiler would follow the spec to the letter, and your C++ code would Just Work(tm) on any toolchain.
It may be that you've got to massage your code, or translate it to another language, or emulate some feature, in order to port your code to that platform.
Neither C nor C++ has a standard ABI last time I checked.The C++ language standard strictly defines semantics of all language constructs. However, it does not specify how these constructs must be implemented at binary level (in object code). As there is no common application binary interface (ABI) standard, C++ compiler vendors have come up their own ABI variations. As a result, problems can arise when object files produced by different compilers are linked together. These problems are usually caused either by the differences in memory layout of compiler-generated data structures, different calling conventions, or differences in name mangling. The main differences of an EABI with respect to an ABI for general purpose operating systems are that privileged instructions are allowed in application code, dynamic linking is not required (sometimes it is completely disallowed), and a more compact stack frame organization is used to save memory.
I remember Stroustroup for example talking about how recursion wasn't allowed on development of JSF.
Another example iPhone. Although garbage collection with Objective-C is fully supported on Mac OS X it isn't on iOS although they now have ARC I believe.
I remember Stroustroup for example talking about how recursion wasn't allowed on development of JSF.
Another example iPhone. Although garbage collection with Objective-C is fully supported on Mac OS X it isn't on iOS although they now have ARC I believe.
Yes it does, you just chose to interpret it differently so you could go off on an arrogant rant.[/quote]
[quote name='Antheus' timestamp='1326829278' post='4903737']This question in such general form doesn't make much sense.
Ok...
SQLite has a Java version. It's pure Java. SQLite is first compiled into ARM assembly, which is then converted into Java bytecode, which then runs inside JVM as Java class. SQLite has precisely zero knowledge of JVM.
C and C++ compilers that generate Intel or ARM assembly are widely available. This step is a non-issue, so they support just about any platform out there. In embedded development there is a whole set of different instruction sets which are technically called ARM, but they are incompatible with each other, yet none of that affects source code.
But in order for them to be of any use, it comes down to the APIs we use, from OS to third party libraries. Hence my claim that question doesn't make sense. C and C++ are not a problem, GCC will compile either of those into your chosen assembly.
But code that is written for POSIX will require POSIX run-time. Something using OGL will require OGL support.
When a new platform comes out, you're usually stuck with the toolchain that's given to you in the official SDK for that platform. If you're a licensed developer for that platform, you may not even have a (legal) choice about using a 3rd party SDK vs the official SDK.
If the official SDK has a buggy C/C++ compiler, or a buggy Java VM, or is missing a C# compiler -- then those are your limitations when it comes to portability.[/quote]
If asking purely about out-of-box experience, then C or C++ is again a non-question. On Windows, portability is defined by Visual Studio. On other platforms by something else, perhaps a proprietary toolchain.
In an ideal world, every C++ compiler would follow the spec to the letter, and your C++ code would Just Work™ on any toolchain.[/quote]
If my code uses DX, it's not portable, even if perfectly standard compliant.
A compiler does absolutely zero for portability. Compiler standard compliance tends to be the least important problem for portability.
Availability of compiler for given platform is just a pre-requisite and with cross-compilation and common targets widely supported not a big one. To do anything interesting, one needs to determine the OS functoinality application makes use of. Again, less of a problem these days as mainstream platforms gravitate towards POSIX. But any library ends up with either assembly or kernel calls. Those determine portability of an application.
This question in such general form doesn't make much sense.
I think what the OP meant to ask was closer along the lines to: "Across different platforms, how standard compliant are the C++ compilers for that platform compared to the standard compliancy of the C compilers for that platform?" If this is indeed what the OP meant, I think SiCrane provided an adequate answer.
[quote name='Antheus' timestamp='1326829278' post='4903737']
This question in such general form doesn't make much sense.
I think what the OP meant to ask was closer along the lines to: "Across different platforms, how standard compliant are the C++ compilers for that platform compared to the standard compliancy of the C compilers for that platform?" If this is indeed what the OP meant, I think SiCrane provided an adequate answer.
[/quote]
That's pretty close to what I was asking (in addition to the question of "if there are C compilers for a system, are there usually C++ compilers too?"). It was about compiler support (i.e. real world language implementations) rather than language specifications (i.e. the ideal, albeit imaginary, implementation).
@Antheus: Of course C++ as a language doesn't dictate any kind of "portability"-ness. I was asking more about the practical, real life implementations of C++ and C -- whether they (particularly C++) exist and if so, how much do they tend to deviate from the standard so I know how much of my code will become invalid. I'm not talking about using particular 3rd party libraries; just straight C and C++, and if there is typically good support for taking this code and producing a runnable executable. You actually talk about my concerns/questions in your post. The compilation, linking, and run-time environments are the concerns, as they limit me in what I can do with a language (i.e. if the compiler doesn't support a language feature, or if the linker has some kind of restriction (maybe how names are decorated, for example) which is critical to the system (can't imagine why, but again, I don't know, which is why I'm asking), or if the runtime environment doesn't have support for the language's standard libraries, etc).
Anyway, thanks for the input everyone! Looks like I'll be writing my renderer in C++ and not C (it's for a school project, FYI, as I wouldn't normally try to reinvent the wheel).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement