Thread: DOS C complier.

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    55

    DOS C complier.

    How to complie c program using DOS? Is there some DOS C complier?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you mean "I want to type in a command from the pretty command prompt window and have it compile" then every compiler has such a thing, even Visual Studio. (What the command is depends upon the compiler.)

    If you mean "Does a compiler come with Windows", then no.

    If you mean "I have a pre-1995 computer that's actually running DOS and I want a compiler", then there are such things but I don't know what they are.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by curious View Post
    How to complie c program using DOS? Is there some DOS C complier?
    You'll want Turbo C/C++ version 1.01, from Borland. It's from from their legacy site. I would avoid Turbo C version 2.0, which preceded it, however.

    Be sure to list all your variables before making assignments to any of them, however:

    Code:
    int i, j;
    i = 0;
    
    char ch;
    Stuff like this will make the Turbo C compiler cough an error that isn't easy to figure out.

    Turbo C/C++ runs in a console (DOS) window in Windows2K, or XP, at least.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It's more likely that you just want to compile your program from the command prompt, I think.

    In that case, assuming you have Dev-C++, try this:
    Code:
    gcc program.c -o program.exe
    If Dev-C++ put its Bin folder in the path, that should work. (Assuming "program.c" is in the current directory.)

    I don't know how you would do this with, say, MSVC. You could search for it, or wait for Elysia to tell you.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't want to compile with MSVC from the command prompt. It's difficult and error prone.
    In case you want to compile from the command prompt, just use gcc/g++ or a similar compiler.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You don't want to compile with MSVC from the command prompt. It's difficult and error prone.
    I dunno. It doesn't look too hard. http://msdn.microsoft.com/en-us/library/610ecb4h.aspx

    You could always use make (or whatever MS calls it) if the commands to type are long. I highly recommend make anyway, even if you're not using the command line to compile your program. (Your IDE might be using make in the background without you even realizing it.)

    You really shouldn't use Turbo C unless you really are using a really old DOS system, however. It has a lot of shortcomings that are easily avoided by using more modern compilers.

    Incidentally, DJGPP (which robwhit linked to) is a port of GCC to DOS, so you can use my Dev-C++ command with it as well.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It may not look like it, but it's far from the truth. You have to put the right compiler options, as well, or you'll get a broken EXE.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, if you feel like taking a stab at it, this looks very comprehensive: http://www.functionx.com/visualc/com...ne/cmdline.htm
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    # Type the following in the empty file:
     
    
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << "\nC++ is Fun!!!\n";
    	return 0;
    }
    
    # Close the project and accept to save each file.
    # On the command prompt, change to the directory in which the file was saved. For me, that would be C:\Programs\MSVC\Exercise1
    # To build the project, type CL main.cpp and press Enter (CL stands for Compile and Link)
    You should receive a series of lines:
     
    
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    
    C:\>CD Program Files\Microsoft Visual Studio\VC98\Bin
    
    C:\Program Files\Microsoft Visual Studio\VC98\Bin>VCVARS32
    Setting environment for using Microsoft Visual C++ tools.
    C:\Program Files\Microsoft Visual Studio\VC98\Bin>CD\
    
    C:\>CD Programs\MSVC\Exercise1
    
    C:\Programs\MSVC\Exercise1>CL main.cpp
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
    Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
    
    main.cpp
    C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\istream(547) : warning C4530: C++ exception ha
    ndler used, but unwind semantics are not enabled. Specify -GX
    C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\ostream(234) : warning C4530: C++ exception ha
    ndler used, but unwind semantics are not enabled. Specify -GX
            C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\ostream(229) : while compiling class-t
    emplate member function 'class std::basic_ostream<char,struct std::char_traits<c
    har> > &__thiscall std::basic_ostream<char,struct std::char_traits<char> >::put(
    char)'
    C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\ostream(234) : warning C4530: C++ exception ha
    ndler used, but unwind semantics are not enabled. Specify -GX
            C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\ostream(229) : while compiling class-t
    emplate member function 'class std::basic_ostream<unsigned short,struct std::cha
    r_traits<unsigned short> > &__thiscall std::basic_ostream<unsigned short,struct
    std::char_traits<unsigned short> >::put(unsigned short)'
    C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\istream(46) : warning C4530: C++ exception han
    dler used, but unwind semantics are not enabled. Specify -GX
            C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\istream(41) : while compiling class-te
    mplate member function 'bool __thiscall std::basic_istream<char,struct std::char
    _traits<char> >::ipfx(bool)'
    C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\istream(46) : warning C4530: C++ exception han
    dler used, but unwind semantics are not enabled. Specify -GX
            C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\istream(41) : while compiling class-te
    mplate member function 'bool __thiscall std::basic_istream<unsigned short,struct
     std::char_traits<unsigned short> >::ipfx(bool)'
    C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\xstring(525) : warning C4530: C++ exception ha
    ndler used, but unwind semantics are not enabled. Specify -GX
            C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\xstring(521) : while compiling class-t
    emplate member function 'void __thiscall std::basic_string<char,struct std::char
    _traits<char>,class std::allocator<char> >::_Copy(unsigned int)'
    C:\PROGRA~1\MIAF9D~1\VC98\INCLUDE\ostream(296) : warning C4530: C++ exception ha
    ndler used, but unwind semantics are not enabled. Specify -GX
            main.cpp(6) : see reference to function template instantiation 'class st
    d::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::operator <<(
    class std::basic_ostream<char,struct std::char_traits<char> > &,const char *)' b
    eing compiled
    Microsoft (R) Incremental Linker Version 6.00.8447
    Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
    
    /out:main.exe
    main.obj
    
    C:\Programs\MSVC\Exercise1>
    LOL.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Congratulations. You created a borked EXE.
    So much for that poor tutorial.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That's a direct quote from the tutorial. It's not a "borked EXE". Apparently, it still runs.

    And anyway, it's being pretty clear, isn't it? Specify -GX on the command line, because you're using exceptions.

    I can't believe it. I'm defending MSVC.

    (I do agree, though; the tutorial probably isn't very good if that's what it's saying . . . .)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dwks View Post
    That's a direct quote from the tutorial. It's not a "borked EXE". Apparently, it still runs.
    Of course it runs. But does it run according to specs?
    And who says it isn't a walking time bomb?
    Have you looked at the command the GUI creates? It's far more complicated and advanced.

    And anyway, it's being pretty clear, isn't it? Specify -GX on the command line, because you're using exceptions.
    You should ALWAYS use that, or disable exceptions altogether. Non-stack unwinding when using exceptions isn't part of the C++ spec, is it?

    (I do agree, though; the tutorial probably isn't very good if that's what it's saying . . . .)
    Cheers. Here's where we do agree.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    My VC doesn't say that at all. It says
    C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc


    I would think that if that's how they compiled the libraries (all we wanna do is std::cout, is that so much to ask?) that would be the default.

    Edit: Man is the OP going to be surprised by this thread.

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Perhaps it's not the default because exception handling is presumably disabled for C programs?

    (But then why wouldn't it be the default for source code with a .cpp extension? . . . .)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File systems?? (Winxp -> DOS)
    By Shadow in forum Tech Board
    Replies: 4
    Last Post: 01-06-2003, 09:08 PM
  2. winver, winminor, winmajor can it be found from dos?
    By ronin in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-02-2002, 10:32 AM
  3. real mode dos & win dos
    By scott27349 in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-19-2002, 06:15 AM
  4. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 01:42 PM
  5. Shut off DOS screen automatically to Windows
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-08-2001, 07:14 PM