I usually use argv[0] or basename(argv[0]) , if possible. From the POV user, I think that if they rename or tightly link the executable file (or someone else does it for them), then they want messages from it to appear under the name that they use, and not under some other the name that it was compiled that they may or may not know.
Similarly, if in the future you find that you want to compile your program under different names with different parameters in order to provide different versions, you want to wrap #ifndef around this #define and make sure it is defined through the Compiler Command Line: -DPROGRAM_NAME=myprog_demo , or do you just want to do it and it works?
An exception may be that if your instructions for use are an extract from a man page or other documentation, you might want to set the name of the program in it. But then you probably would not use #define .
Implementations should not provide argv[0] , though, so this case is also handled for better portable methods. Again, if your system does not provide it, then probably the user will also not see messages on any terminal.
By the way:
#define PROGRAM_NAME "myprog" puts("this is " PROGRAM_NAME);
Steve jessop
source share