inline

M

Mark

Hello

is it required to have 'inline' keywoard before type in a function
definition/declaration? For example, what is correct:

inline int small_func(void)
{
/* do something */
}

or

int inline small_func(void)
{
/* do something */
}

Also - is the same true for functions having static definition?

Thanks.

Mark
 
B

Ben Pfaff

Mark said:
is it required to have 'inline' keywoard before type in a function
definition/declaration? For example, what is correct:

inline int small_func(void)
{
/* do something */
}

or

int inline small_func(void)
{
/* do something */
}

Both are correct but the former is customary.
Also - is the same true for functions having static definition?

Same answer.
 
M

Mark

Ben Pfaff said:
Both are correct but the former is customary.

For the second case "gcc -std=c99 -pedantic -W -Wall" gives warning: 'inline'
is not at beginning of declaration. Why does gcc care about the sequence if
both representations are correct ?
Thanks.

Mark
 
B

Ben Pfaff

Mark said:
For the second case "gcc -std=c99 -pedantic -W -Wall" gives
warning: 'inline' is not at beginning of declaration. Why does
gcc care about the sequence if both representations are correct
?

It's customary to put 'inline' at the beginning. GCC is
suggesting that you might have made a mistake. It's a warning,
not an error, so you can ignore it or turn it off if you prefer
to use an unusual ordering.
 
K

Kaz Kylheku

For the second case "gcc -std=c99 -pedantic -W -Wall" gives warning: 'inline'
is not at beginning of declaration. Why does gcc care about the sequence if
both representations are correct ?

gcc doesn't provide warnings about only what is incorrect, but also
stylistic warnings. This is also correct:

(a && b || c)

So is this

while (x = 0) { ... }

The above could be potential bugs, though.

Furthermore, some of GCC's warnings also helps with portability issues. Inline
functions were an extension in many C compilers for a long time. Maybe not all
C compilers with an inline extension allowed the keyword to be in any position
among the specifiers.

This might be something that has been in GCC for some time. It's also issued
for the GNU C dialect (that you get if you don't use -ansi or -std=c99).
The minimal set of options that obtain this warning are:

gcc -W foo.c

By the way, I also tried the C++ front end (gcc 4.4.1) and see that it does
not have such a warning. It's implemented in the C front end only.
 
K

Keith Thompson

Mark said:
For the second case "gcc -std=c99 -pedantic -W -Wall" gives
warning: 'inline' is not at beginning of declaration. Why does
gcc care about the sequence if both representations are correct ?

C99 6.11.5 says:

The placement of a storage-class specifier other than at the
beginning of the declaration specifiers in a declaration is an
obsolescent feature.

This doesn't apply to function declarations, but I would think that the
placement of "inline" should be treated similarly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top