locked
A Simple Question about C++ RRS feed

  • Question

  • Im going to be having difficulties explaining this question but is relatively simple if you understand what I mean...

    I am in year 11 and have taught myself VB.net just from the internet so far, so I know a lot of VB.net programming but I do not know anything advanced like how native code works. I am considering moving onto some simple C++ to get some native applications going without the need of the .net Framework.

    My question is how do video games/software today (whether it would be a indie game/retail game/open source software or proprietary software) run on computers without the .net Framework and do not require any run-times, some are even cross-platform. Because I am finding it really difficult just to develop a simple native hello world C++ and compile it with the visual studio command line (cl). I know most of these applications would run with C++ code but how is this possible. Is all code done in no development environments? Also what is the best way to develop native code applications (C++/C#)?

    Reason of this question:
    1. Always wondered since I started programming
    2. Distributing native code applications would be excellent because getting peers to forcefully install .net framework is a pain.

    (Yes I am aware that the .net Framework provides ALSO of useful classes etc... to make programming much easier)

    Thanks,
    Xanather :)
    Take a look at my site: http://www.xanather.com
    Friday, May 6, 2011 4:40 PM

Answers

  • If you stick with standard C++ it is pretty cross platform. (You obviously need to recompile your sources for every target, but the source code itself is cross platform).

    When people write cross platform games in C++ what they are doing is typically:

    • stick with standard C++
    • don't rely on processor specific tricks
    • Do use 3rd party libraries (e.g. game engines, physics engines, rendering packages) that are available on multiple platforms
    • Take the stuff that has to be platform specific and abstract it away as much as possible. (The result will be that you would have a few source files that are specific to each platform, but 95% of your source would be common to all platforms).

    Now, this is pretty much a decision to be made up front, you aren't going to be very successful taking your Win32 MFC app and getting it to run on Linux (short of a WINE type solution).


    With native code you have the possibility to actually compile all of your runtime dependencies into the app, so that you don't have to distribute a runtime like the .NET runtime. 
    • Marked as answer by Xanather Saturday, May 7, 2011 1:53 AM
    Friday, May 6, 2011 4:51 PM

All replies

  • Any game or any package for that matter will consist of an installation which will install all the necessary dependencies like the .Net framework.

    So the user simply runs the installer and it installs all the necessary software without the user needing to download and install them separately.

    As for games not using the .Net framework, you can use DirectX or OpenGl.


    «_Superman_»
    Microsoft MVP (Visual C++)

    Polymorphism in C
    Friday, May 6, 2011 4:44 PM
  • If you stick with standard C++ it is pretty cross platform. (You obviously need to recompile your sources for every target, but the source code itself is cross platform).

    When people write cross platform games in C++ what they are doing is typically:

    • stick with standard C++
    • don't rely on processor specific tricks
    • Do use 3rd party libraries (e.g. game engines, physics engines, rendering packages) that are available on multiple platforms
    • Take the stuff that has to be platform specific and abstract it away as much as possible. (The result will be that you would have a few source files that are specific to each platform, but 95% of your source would be common to all platforms).

    Now, this is pretty much a decision to be made up front, you aren't going to be very successful taking your Win32 MFC app and getting it to run on Linux (short of a WINE type solution).


    With native code you have the possibility to actually compile all of your runtime dependencies into the app, so that you don't have to distribute a runtime like the .NET runtime. 
    • Marked as answer by Xanather Saturday, May 7, 2011 1:53 AM
    Friday, May 6, 2011 4:51 PM
  • As to why it works. Windows provides some of the features. DirectX and opengl are part of a modern Windows system. It is just the convenience classes which are part of the DirectX SDK requires any dependencies. The games also make use of other services provided by Windows as part of the Win32 API.

    For C++ itself, it does have one dependency, but C/C++ supports statically linking this (making it part of the executable file itself), so even that may not be an issue. It is also possible to just place these files in the directory*.

    So that is how native programs can get away with less dependencies.

    *With VS2005 and 2008, is was possible but private assemblies could be awkward, so use at your own risk.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    Friday, May 6, 2011 6:12 PM
  • Thank you all. All your posts were helpful.

    Although...
    What is the best way to develop standard/native C++ (what IDE?) or is it usually done with a simple source code editor/notepad?

    Thanks!
    Take a look at my site: http://www.xanather.com
    Saturday, May 7, 2011 1:58 AM