I've read the first array member of argv will always be the program name.
It should be. C and C++ both require that if argc
is greater than zero, argv[0]
shall either be the program name or an empty string.
Some systems do not necessarily follow this convention in all circumstances (on Windows, for example, you can use CreateProcess
to create a new process and not pass the program name in the command line arguments that are used to populate argc
and argv
).
Is it ever useful to hang on to this?
Sure. If you want to spawn another instance of yourself, for example, or if you want to print your program name (for example in usage instructions).
Do people ever unshift the first member because it is useless, or is leaving it there best practice?
Don't change the actual arguments; the next person who comes along will probably be expecting them to be in their original form.