5

All modern compilers (clang 3.6, gcc 4.8) allow writing functions with an _ in arguments' list. Like this:

int func(_) { return 1; } 

Even main allows such argument (int main(_))

The only warning is

p1_concat.c:31:5: warning: type of ‘_’ defaults to ‘int’ [enabled by default]

What does this underscore mean?

1
  • It's just a variable name, like any other. The compiler doesn't treat it specially. Sometimes people use it for variables whose value isn't used, but that's purely a convention and more common in other languages. The warning is just what it says, and you'd see the same thing if you used any other name, e.g. x. Commented Feb 17, 2016 at 12:47

2 Answers 2

4

The underscore _ is a valid, ordinary identifier. Defining a function like this:

type function(arg1, arg2, arg3) { ... } 

(i.ee without parameter types) is a deprecated style back from the pre-ANSI days called a K&R-style definition. All parameters implicitly have type int unless you explicitly declare them to have a different type like this:

type function(arg1, arg2, arg3) type arg1; type arg2; type arg3; { ... } 

where type arg1; is an ordinary declaration. These definitions are still allowed but deprecated. Because you didn't explicitly declare _, the compiler warns you about the implicit declaration as int.

Sign up to request clarification or add additional context in comments.

Comments

0

This

int func(_) { return 1; } 

is a function definition with an identifier list consisiting from one identifier with name _ (underscore).

It is not a correct function definition. According to the C Standard (6.9.1 Function definitions)

6 If the declarator includes an identifier list, each declaration in the declaration list shall have at least one declarator, those declarators shall declare only identifiers from the identifier list, and every identifier in the identifier list shall be declared.

It would be more correctly to define the function for example like

int func(_) int _; { return 1; } 

As for the similar definition of main

int main(_) { //... } 

then it is not a valid declaration of main even if to add definition of the identifier _ like it is done above

int main(_) int _; { //... } 

The C standard does not allow to declare main with an identifier list. At least it is not a standard declaration of main.

1 Comment

You should never write "K&R style" functions. It is an obsolescent feature as per 6.11.7.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.