New to C++

This is a discussion on New to C++ within the C++ Programming forums, part of the General Programming Boards category; What exactly does a complier do? does it create the file to make the game/program or is it needed to ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    New to C++

    What exactly does a complier do? does it create the file to make the game/program or is it needed to actually make the source code??? please respond some one

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    Re: New to C++

    Originally posted by Prophecy_OD_
    What exactly does a complier do? does it create the file to make the game/program or is it needed to actually make the source code??? please respond some one
    a compiler is used to compile the source code that you or someone else has written, and then turns it into language the computer can understand, and then turns that into a program...

    also...welcome to c++, hopefully you find it enjoyable.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Adding to what alpha said and answering your last question, you technically dont need a compiler to write your code. You can write your code in word or even notpad. however if you want to actually run your code and check for errors and stuff then you would need a compiler.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Compiling is only half the process, each module also has to be linked in order to be able to form one single executable after compilation is complete.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    The computer doesn't understand C++ The compiler translates.

    You might have heard someone say that computers only understand ones and zeros (the binary system). In the old days (even before I started programming) programmers actually programmed the ones and zeros. Then, they found it was easy to convert between base-8 and binary. Everything was done with base-8 numbers. So there was some base-8 number that meant "ADD"... and a different number for each "machine language instruction". Nowadays if we're going to use the fundemental numbers, we use base-16 (=hexadecimal = hex).

    It didn't take long to figure out how write a program (written with the machine-code instructions) to convert a simple english-like instruction (i.e. ADD) to the machine-language "number". This one-for-one english-like language is called ASSEMBLY LANGUAGE.

    Then, they figured-out how to make a program (written in assembly) that could convert more-english-like instructions to machine language. These are COMPILERS and they convert "HIGH LEVEL LANGUAGES" like C++, BASIC, Fortran, Pascal, COBAL, etc.

    A compiler takes a single high-level language instruction and converts it into (typically) several machine-language instructions.

    So, you write your C++ program and save it as MyProgram.CPP The computer can't "run" your program yet. You process your program through your compiler, and the compiler generates a file named MyProgram.EXE . When you click-on MyProgram.EXE, your program runs and displays "Hello World" on the screen (for example).

    [EDIT] - Don't worry too much about linking yet... the compiler will link automatically.
    Last edited by DougDbug; 01-29-2003 at 06:49 PM.

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Actually, a compiler won't link things automatically. A compiler won't make executables. Compiling AND linking must be done. Most programs which compile will link for you as well, but not necissarily. They are still very separate processes. Not all C++ projects are linked because not all are meant to be executables (IE static link libraries).

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> the compiler will link automatically.

    The compiler will not link automatically. If you are using an integrated IDE, the IDE, depending on your settings, may run the linker automatically, but if you are using command line tools, like the freebie Borland stuff, you will need to run the linker.

    Even using an IDE which handles the linking for you, you may need to specify which libraries you should link with. Something that crops up weekly on the Windows board is "I get a link error when I compile my common controls program", meaning that they have not added comctl32.lib to their linker options.

    I agree that using an IDE and a simple Hello World program, knowledge of the mechanisms is not strictly necessary, but that is no real excuse.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Actually, a compiler won't link things automatically
    Don't you think we've confused the poor guy enough already?

    My point is that 99% of the time, ONE CLICK (or one command line) and BAM I've "automatically" converted a cpp to an exe.

    I assume Prophecy_OD_ is asking because he wants to start programming, not because he wants to write a technical paper. I respect your a knowledge, Polymorphic OOP, and I'm NOT going to get into an argument with you, because that's NOT why I'm here! (I'm here to learn and to help.)

  9. #9
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    There are two steps: compilation and linking. If you're in DOS, then you do them seperatly. But most IDEs do all that automatically for you. So when you press the 'Go' Button (or 'Run', or F5, or Ctrl-F5, etc ), the IDE will all that for you can boom, the application will run right in front of your eyes if there are no errors.

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> confused the poor guy enough already

    I appreciate your point, but, start people off with an incorrect premise, and they will have trouble later on, start them right, they won't.

    Things like the Borland tools are very commonly used by beginners, because they are free. Unless you are using the make facilities, you will need to compile and link.

    One could just as easily ask why bother telling him about the assembler created by the compiler, surely, by your own argument, the compiler does all of that automatically. Again, I am not saying he shouldn't know that.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Yeah, and it's one thing not to mention it at all, but it's another thing to speak of it, but speak of it improperly. It's better to learn something properly and be a little bit confused than it is to learn it improperly and be able to get by for a while and then have to unlearn what you thought was correct. It's best to just make the distinction from the start.

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    2
    Thanks for answering my questions, I got bore dof web scripts and such and I am looking forward to scripting programs

  13. #13
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    Talk about bringing up an old topic

    I was searching through the forums trying to find an answer to my question. This thread seemed to answer them. Just one last thing.
    Refering to this quote:

    adrianxw
    Even using an IDE which handles the linking for you, you may need to specify which libraries you should link with.
    I'm using a borland compiler, and i don't need to specify the libraries i need to link to, but there are a lot of library files in my lib directory. My question is this:

    Is there always one specific library that links to my program?
    Or
    Does the linker search through all the library files until it comes across the one(s) with the correct definitions?
    Or
    is there something ( like the compiler or header files) that specifies certain library files based on the library functions used?
    Or
    Other?
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21