Thread: large exe file, and general C++ newbie confusion

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    6

    large exe file, and general C++ newbie confusion

    Hi, I'm just starting out with C++, although I've been programming PHP for ages (so i know functions, looping, etc), and a little bit of C, but there's a few things i'm struggling with. I've just started working through a book "Beginning Game Programming", and while i understand 90% of the code itself, it's little things like the types of files (.h, .o etc), indeciferable compiler errors, loopbacks, ::, etc, should i buy a C++ book and start from scratch, or will i pick these things up as i go? I've looked through a LOT of tutorials, and all the ones i've read cover specifics like variables, looping, etc very clearly, except these little nuances tend to go unnoticed

    One specific problem, everything I compile comes out huge, for example:
    Code:
    #include <iostream.h>
    
    int main()
    { 
        char x;
        cout << "Type c and press enter";
        cin >> x;
    }
    comes out at 463kb. I'm using the latest Bloodshed Dev-C++, everything at default. what might i be doing wrong before i get into making bigger stuff? Also, although it's compiling fine, i get warnings like "...at least one antiquated or deprecated header..."

    i hope at least something i said has made sense :S sorry

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> #include <iostream.h>
    Change that to <iostream>, and put a

    using namespace std;

    on the next line (for simplicity. You'll understand what that is later, don't worry about it for the moment). Main() should also return something. Normally, one returns 0, so before the final }, just throw in a 'return 0;'

    These won't help you with the size of your file, but it's just something to keep in mind. deprecated header, that's iostream.h

    You know the way in php you can include "myFile.whatever"; and you have access to that file? You can get functions from it if it's another PHP file etc, well, that's the same thing with the #include <whatever>. The .h specifies that it's a header file.

  3. #3
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    I don't really know about this compiler, but I think the message justs means that your header is just ...deprecated. Maybe it means that you shouldn't write ".h" in it, as it is a standard header file, you don't really need to add the ".h" to "iostream". Most of the standard headers found out in your compiler's directory only require you to write "<file>" without writting the extension...
    Code:
    #include <iostream> //Good
    #include <iostream.h> //Not good
    As for the .exe size, it sure looks big, but if your app is compiled under debugging settings, it will always be bigger. Once your app is fully debugged, you just use "releasing" settings so your app will optimize itself, and at the same time, taking less space on your drive.

    I don't know how this apply to your compiler, but normally you can't debug your app while you have settings that enables optimization for your program.

    Hope that's clear, don't give up on doing this: it is certain that you can buy a book, but if you are able to understand the examples you see, maybe you will be able to get through it!

    Edit: Sorry if some things have already been said!
    Last edited by mikahell; 09-02-2006 at 06:39 AM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    6
    aha, i knew i was missing something with the namesapces, thank you i'd read that line before, "using namespace std" but didn't know what it applied to, without it, it claims that the function isn't declared, so obviously the header is using that namespace to declare the functions.

    is there anything special about a header file? in php, an include is just another php file, can contain anything, but i get the impression .h files are somehow special?

  5. #5
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Not really different from ".cpp", or ".c" files, though they mostly contain class definitions and functions, though that's just some sort of convention: you put the stuff you don't want to see in your main ".cpp" file in headers, so you can easily see what you'r doing.

    You can, but you are not forced to use a namespace, it is just a way to avoid writting the namespace for every occurences of functions / classes that are in the namespace, such as this:

    Code:
    std::cout << "Type c and press enter";
    std::cin >> x;
    
    //or you can also have this:
    using namespace std;
    //...
    cout << "Type c and press enter";
    cin >> x;

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    6
    okay, i can't find anything regarding debugging, but i found some optimization setting that dropped it to 250kb, so it's obviously a Dev-C++ thing, not the code, so i'll read through the help file tomorow, thanks for pointing me in the right direction

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    6
    aha, so that's what the :: means! it's all starting to come together now

    so, just to clarify, your "main()" file will be .cpp, and and any other included code, function definiteions etc, you put in a .h file? that makes sense, thanks

    thank you guys, unbelievably helpful forum!

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    That's odd, I have a 475 kb exe.... but that should be normal for me since I have a GUI and 100++ lines of code, I don't know why your getting your file so large, you prob enabled debugging without knowing it.

  9. #9
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    That's good! Now I just forgot one thing, you should use "using namespace std;" but you don't have to use the whole namespace. You can choose to only use the std members that you only need, that are for now cin and cout.

    Code:
    using std::cout;
    using std::cin;
    Though if you have too many, just include the whole lot of it. I don't think it will change the .exe file size, but as you are learning, it will probably help to know in which namespace are functions XYZs...

  10. #10
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Quote Originally Posted by bikr692002
    That's odd, I have a 475 kb exe.... but that should be normal for me since I have a GUI and 100++ lines of code
    I'd say that it also depends about if your functions are inlined, and also maybe if your code has many lines, it doesn't mean that there is not a lot of comments... But normally that should be proportional

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    6
    LOTS to remember, namespaces, object instances, pointer, it's a whole world above PHP, but i'm kind of enjoying it

    The reason I'm learning is I've always, always, wanted to make a game, and FlashMX is just agonisingly inneficient, and I've got a professional animator friend that wants to get onboard too, so i'll keep you all posted (and i'm certain i'll be asking more questions too). if i can find a few spare dollars, i might invest in a pure c++ book

  12. #12
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    in php, an include is just another php file, can contain anything, but i get the impression .h files are somehow special?
    In general there is no difference. #include does the same as in php ( I guess ) The preprocessor just replaces the include directive with the contents of the file before it is passed to the compiler.
    But then yes .h files are somehow different from other source files. That is because of how c or c++ compilers work. A c compiler doesn't produce any directly executable code, it only compiles source modules to object-modules and a linker takes care of producing the executable. You generally want a header to be reusable when compiling different source-modules. So you have to make shure that a header doesn't include any actual code ( other then inline declared code ). It should contain only declarations. Also you have to protect the contents of the header against multiple inclusions ( look up "include guards" ). And it gets a little more complicated if you want to use a c++ compiler to use headers that were written for c libraries ( look up extern "C" and name mangling ).
    Kurt

  13. #13
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    FlashMX is just agonisingly inneficient
    Well, it is certain that Flash is slow and stuff, but that's because it is really easy to work
    with. But when you step in the C++ programming for games, you will realize very fast that's a lot of headaches. C++ is really low-level compared to Flash, as you'll find out quickly.

    But consider that when you are able to create a game out of C++, you're far more proud of your work since it is harder. But if you need some basic 2d engine, I'd suggest you the SDL library, though maybe you will have problems with using library and things since you seem to be at the point of understanding includes... But here is the link: http://www.libsdl.org/index.php

    Cheers

  14. #14
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> it's a whole world above PHP
    There are striking similarities bwtween C and PHP! I mean fopen, fgets, fclose etc etc etc. But pointers and all that kind of jazz, yeah.


    >> LOTS to remember, namespaces, object instances, pointer,
    It may seem daunting at first, but it's not really all that hard to remember things like that. I mean, with GUI, I don't think anyone memorises most of main!! Just copy and paste. Well, that's in my limited windows programming experience. I've also found that those exe's are much smaller than console ones, oddly enough. I don't get it, but there we go.

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    6
    Thank you guys, i really appreciate you taking the time to help clarify those bits and pieces for me now it's just gona be a case of practise practise practise

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. General Guidelines on Preventing Header File collision
    By stanlvw in forum C++ Programming
    Replies: 12
    Last Post: 07-05-2008, 04:02 AM
  3. general C++ help - compilers, file access etc
    By scary_dave in forum C++ Programming
    Replies: 6
    Last Post: 05-06-2006, 09:03 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM