I am reading codes of mcachefs and could not understand some codes, like below:
printf("mcachefs " __MCACHEFS_VERSION__ " starting up...\n");
if (argc == 1 || argv[1][0] == '-')
{
fprintf(stderr,
"\tError : first argument shall be the the mcachefs_mountpoint !\n");
exit(2);
}
I have two questions:
1: For printf("mcachefs " __MCACHEFS_VERSION__ " starting up...\n"), is it the correct way to use printf? I have never seen such way of using it.
- What is the meaning of
argv[1][0]? I knowargv[]represents the arguments from the command line. But, is not it a one dimension array?
When the C compiler sees a lot of string literals next to each other, it concatenates them into one long string. So that use of
printf()is OK, as long as the macro__MCACHEFS_VERSION__expands to a string. That string had better not contain any percent characters… I’d write it asprintf("mcachefs %s starting up...\n", __MCACHEFS_VERSION__);As others have pointed out,
argv[1]is the second string in the string arrayargv, and strings are character arrays soargv[1][0]is the first character in the second string.