• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Cornstalks

Portability of C++ Compared to C

13 posts in this topic

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!
0

Share this post


Link to post
Share on other sites
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.
-4

Share this post


Link to post
Share on other sites
[quote name='Dunge' timestamp='1326824551' post='4903707']
iPhone never supported C, it only support Obj-C (Apple way of beeing "different").
[/quote]
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.
1

Share this post


Link to post
Share on other sites
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.
-2

Share this post


Link to post
Share on other sites
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. Edited by daviangel
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1326843772' post='4903829']
[quote name='Antheus' timestamp='1326829278' post='4903737']This question in such general form doesn't make much sense.[/quote]Yes it does, you just chose to interpret it differently so you could go off on an arrogant rant.[/quote]

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.

[quote]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.

[quote]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.
0

Share this post


Link to post
Share on other sites
[quote name='Antheus' timestamp='1326829278' post='4903737']
This question in such general form doesn't make much sense.
[/quote]
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.
0

Share this post


Link to post
Share on other sites
[quote name='bronxbomber92' timestamp='1326854166' post='4903864']
[quote name='Antheus' timestamp='1326829278' post='4903737']
This question in such general form doesn't make much sense.
[/quote]
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).
0

Share this post


Link to post
Share on other sites
Portability goes out the window very quickly, as you almost always have to work with a platform-specific API to implement anything useful.

Choosing what platforms you want to support should come first. From there, you can propose a strategy to meet those requirements.
0

Share this post


Link to post
Share on other sites
[quote name='daviangel' timestamp='1326845396' post='4903840']
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.
[/quote]
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.
0

Share this post


Link to post
Share on other sites
Just to throw this out there, Android only recently received STL, RTTI, and Exception support. Many embedded systems don't include support for these 3 things off the bat, and many never get them at all.
0

Share this post


Link to post
Share on other sites
[quote name='jonbonazza' timestamp='1327007432' post='4904366']
Just to throw this out there, Android only recently received STL, RTTI, and Exception support. [/quote]
You don't mean Android, you mean a C++ compiler for Android. Which one are you referring to?
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0