Command Line On C++'s Main Function.

This is a discussion on Command Line On C++'s Main Function. within the C++ Programming forums, part of the General Programming Boards category; Hey guys. Unfortunately, I am C++ Newb. I have only been learning it for about 6 months or so. Anyways ...

  1. #1
    Registered User Vermillion's Avatar
    Join Date
    Aug 2008
    Location
    Bolivia
    Posts
    3

    Command Line On C++'s Main Function.

    Hey guys. Unfortunately, I am C++ Newb. I have only been learning it for about 6 months or so.

    Anyways back on the road, will I ever need to use a complete Main function deffinition in programs that have nice GUIs and everything?

    Code:
    int main ( int argc, char *argv[] )
    Or is that only for programs that work only on the DOS window?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Even GUI programs can be started from the command line.

    Even something simple like
    notepad.exe myfile.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,456
    Note how, when you double-click a file in explorer in Windows, notepad opens that text file?
    That's because the file is sent via the command line!
    notepad.exe %1
    So it's definitely there, even for GUIs.
    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.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, as others have said, yes. However, Windows GUI applications do not start at "main", they start at "WinMain()", which has a different format for command line arguments.

    See this: http://msdn.microsoft.com/en-us/libr...59(VS.85).aspx

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,188
    However, Windows GUI applications do not start at "main", they start at "WinMain()", which has a different format for command line arguments.
    O_o

    Only if the programmer wishes to use 'WinMain' as the starting point; nothing provided by 'WinMain' is magic.

    Soma

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by phantomotap View Post
    O_o

    Only if the programmer wishes to use 'WinMain' as the starting point; nothing provided by 'WinMain' is magic.

    Soma
    Sure, but it's customary to use WinMain rather than main. I agree that it's not compulsory.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,456
    Some compilers don't allow windows apps without winmain (yes, I'm looking at YOU, GCC). The linker simply complains it can't find WinMain, even if there is a main.
    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.

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,188
    Some compilers don't allow windows apps without winmain (yes, I'm looking at YOU, GCC). The linker simply complains it can't find WinMain, even if there is a main.
    Nonsense. There may be some suite that requires 'WinMain', but I doubt it.

    Soma

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,456
    I'll be happy to change that if someone shows how it's possible to do it w/o WinMain with GCC.
    Last I tried, I just got linker errors (using C::B as IDE and GCC as 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.

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,188
    The IDE is the problem; with GCC at the console, it works by default.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

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