Thread: argv[0] contains command name -- why?

  1. #1
    Registered User
    Join Date
    Apr 2008

    argv[0] contains command name -- why?


    I'm trying to figure out specifically WHY argv[0] contains the command name. I've done a bit of searching and all I can find is that it's a convention, but I'm thinking that there must be another reason. Please let me know if I'm wrong.


  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Because the C and C++ standards say that it can.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Fair enough... thanks.

  4. #4
    Registered User
    Join Date
    Apr 2008

    Symbolic Links

    Many programs are called by symbolic (or hard) links of different names. An example is 'vim.' The executable name is 'vim' but there is usually a symbolic link named 'vi'. The program checks argv[0] to see how it was called. If it was called with 'vi' it acts like 'vi' else it acts like 'vim'. Busybox also uses this technique so that it can use one executable to pretend to be may of the normal *nix utilities that we know and love.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. use of softlink and argv[0]
    By MK27 in forum C Programming
    Replies: 14
    Last Post: 02-24-2009, 04:56 PM
  2. Replies: 12
    Last Post: 02-10-2009, 02:14 PM
  3. main() ; argv[1] = string at argv[0]???
    By UCnLA in forum C Programming
    Replies: 1
    Last Post: 03-31-2008, 12:16 AM
  4. argv[0] with WinMain()
    By dwks in forum Windows Programming
    Replies: 4
    Last Post: 03-05-2006, 12:41 PM
  5. change argv[0] after fork
    By garion in forum C Programming
    Replies: 2
    Last Post: 02-05-2006, 10:29 PM