Portability of C++ Compared to C
#1 Moderator* - Reputation: 5335
Posted 17 January 2012 - 11:43 AM
Thanks!
#2 Moderators - Reputation: 6622
Posted 17 January 2012 - 11:53 AM
#3 Members - Reputation: 329
Posted 17 January 2012 - 12:22 PM
As SiCrane said however, supported features could be different on some platform. No really a problem for future products, but mostly for older.
#4 Members - Reputation: 275
Posted 17 January 2012 - 12:30 PM
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.iPhone never supported C, it only support Obj-C (Apple way of beeing "different").
#5 Members - Reputation: 2369
Posted 17 January 2012 - 01:41 PM
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.
#6 Moderators - Reputation: 13458
Posted 17 January 2012 - 05:42 PM
Yes it does, you just chose to interpret it differently so you could go off on an arrogant rant.This question in such general form doesn't make much sense.
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 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.
#7 Members - Reputation: 600
Posted 17 January 2012 - 06:09 PM
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.
Edited by daviangel, 17 January 2012 - 06:25 PM.
#8 Members - Reputation: 2369
Posted 17 January 2012 - 06:28 PM
Yes it does, you just chose to interpret it differently so you could go off on an arrogant rant.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.
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.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.
If my code uses DX, it's not portable, even if perfectly standard compliant.In an ideal world, every C++ compiler would follow the spec to the letter, and your C++ code would Just Work™ on any toolchain.
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.
#9 Members - Reputation: 275
Posted 17 January 2012 - 08:36 PM
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.This question in such general form doesn't make much sense.
#10 Moderator* - Reputation: 5335
Posted 18 January 2012 - 12:22 AM
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).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.
This question in such general form doesn't make much sense.
@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).
#11 Members - Reputation: 360
Posted 18 January 2012 - 04:14 AM
Choosing what platforms you want to support should come first. From there, you can propose a strategy to meet those requirements.
#12 Members - Reputation: 544
Posted 18 January 2012 - 09:43 AM
ABI conventions come into play when we are starting to look at generated code, as opposed to pure source code. ABI rarely affect your ability to write higher level code, so I'm not sure why anyone would be too concerned about it. The most impact it had in my experience is passing function pointers around and declaring functions with variadic argument lists. In those cases you are forced to disable any language/platform extensions for those particular functions, such as fastcall, etc.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.
#13 Members - Reputation: 117
Posted 19 January 2012 - 03:10 PM
Bonafide Software, L.L.C.
Fairmont, WV 26554 US






