Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is `int main(int argc, char* argv<::>)` a valid signature of main? [duplicate]

Tags:

c++

c

main

I've seen in a site that int main(int argc, char* argv<::>) can also be used as a signature of main. Surprisingly, The following program:

int main(int argc, char* argv<::>)
{
  return 0;
}

compiles withput any warnings in GCC , as well as clang. It also compiles in C++.

So, how is it that int main(int argc, char* argv<::>) is a valid signature of main?

like image 722
Spikatrix Avatar asked Apr 26 '15 06:04

Spikatrix


People also ask

What does int main int argc char * argv meaning?

Command-line Arguments: main( int argc, char *argv[] ) Here argc means argument count and argument vector. The first argument is the number of parameters passed plus one to include the name of the program that was executed to get those process running.

What is argc and argv in main () function?

The first parameter, argc (argument count) is an integer that indicates how many arguments were entered on the command line when the program was started. The second parameter, argv (argument vector), is an array of pointers to arrays of character objects.

What does char * argv mean?

The declaration char *argv[] is an array (of undetermined size) of pointers to char , in other words an array of strings. And all arrays decays to pointers, and so you can use an array as a pointer (just like you can use a pointer as an array).

What does argv mean in C?

What is ARGV? As a concept, ARGV is a convention in programming that goes back (at least) to the C language. It refers to the “argument vector,” which is basically a variable that contains the arguments passed to a program through the command line.


1 Answers

char* argv<::> is equivalent to char* argv[]. <: and :> used here are digraphs.

C11: 6.4.6 (p3):

In all aspects of the language, the six tokens79)

<: :> <% %> %: %:%:

behave, respectively, the same as the six tokens

[ ] { } # ##

except for their spelling. 80)


Foot note:
79) These tokens are sometimes called ‘‘digraphs’’.
80) Thus [ and <: behave differently when ‘‘stringized’’ (see 6.10.3.2), but can otherwise be freely interchanged.

An example:

%: define  stringize(a) printf("Digraph \"%s\" retains its spelling in case of stringization.\n", %:a)    

Calling the above macro

stringize( %:);  

will print

Digraph "%:" retains its spelling in case of stringization.
like image 136
haccks Avatar answered Oct 16 '22 01:10

haccks