Does ANSI-C not know the inline keyword?

Nico Schlömer picture Nico Schlömer · Aug 28, 2012 · Viewed 8.9k times · Source

When compiling something as simple as

inline int test() { return 3; }

int main()
{
 test();
 return 0;
}

with gcc -c test.c, everything goes fine. If the -ansi keyword added, gcc -ansi -c test.c, one gets the error message

test.c:1:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’

This is true even if the C99 standard is explicitly selected, gcc -std=c99 -ansi -c test.c.

What is the reason for this, and is there a recommended fix?

Answer

Reed Copsey picture Reed Copsey · Aug 28, 2012

You need to use:

gcc -std=c99 -c test.c

The -ansi flag specifies c90:

The -ansi option is equivalent to -std=c90.

ANSI C was effectively the 1990 version of C, which didn't include the inline keyword.