user1759085
user1759085

Reputation: 11

clang++ : C++ requires a type specifier

I can't get over this 'C++ requires a type specifier for all declarations' issue with clang++ Please suggest to overcome this error using clang++. I greatly appreciate you, for taking look at it

:>clang++ --version
clang version 3.1 (tags/RELEASE_31/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix


:>cat f.cpp
main(int argc, char** argv)
{
int A;
}



:> clang++ f.cpp
f.cpp:1:1: error: C++ requires a type specifier for all declarations
main(int argc, char** argv)
^~~~
1 error generated.

:> clang++ f.cpp -std=gnu++98
f.cpp:1:1: error: C++ requires a type specifier for all declarations
main(int argc, char** argv)
^~~~
1 error generated.


:> clang++ f.cpp -std=c++11
f.cpp:1:1: error: C++ requires a type specifier for all declarations
main(int argc, char** argv)
^~~~
1 error generated.

:> clang++ f.cpp -std=c++0x
f.cpp:1:1: error: C++ requires a type specifier for all declarations
main(int argc, char** argv)
^~~~
1 error generated.

Upvotes: 1

Views: 6475

Answers (2)

A. K.
A. K.

Reputation: 38146

You are invoking the C++ compiler (clang++). In c++ it is illegal to not have a return type for main. If it is a C program then it will be fine.

Use clang -x c f.cpp

This will just emit warning in this case.

If you want to get rid of warning then do clang -Wimplicit-int -x c f.cpp

Upvotes: 2

ppeterka
ppeterka

Reputation: 20726

You need to specify the return type for the main function!

int main(int argc, char** argv)
{
    int A;
}

Upvotes: 1

Related Questions