Is there a data type in C++ called inline?

W

Wah-chi Lai

Hello all,

I saw a function in a book with the return type is 'inline'. Is that a data
type? How to use it? Where can I find further information about it?

Thanks.
 
J

JKop

Wah-chi Lai posted:
Hello all,

I saw a function in a book with the return type is 'inline'. Is that a
data type? How to use it? Where can I find further information about
it?

Thanks.


"inline" is not a type.


When you turn:

int Blah()
{
return 76;
}


into:


inline int Blah()
{
return 76;
}


Then... what this does is suggest to the compiler that wherever "Blah" is
called in your code, eg:

int main()
{
Blah();

SomeOtherFunctThatCallsBlah();
}


that instead of there being an actual "function call" executed, the code for
blah is sort-of copy-pasted into where it's called. People do this in the
aim of creating a faster executable. Ofcourse there's all sorts of debate on
this...


Note that "inline" only suggests this to the compiler - the compiler is free
to ignore it.


-JKop
 
R

Ron Natalie

Wah-chi Lai said:
Hello all,

I saw a function in a book with the return type is 'inline'. Is that a data
type? How to use it? Where can I find further information about it?
inline isn't a type, but it's what you're seeing is an anachronism.

It used to be legal in C to omit an explicit type if you had a
declaration that was otherwise syntactically valid. The implicit
type was int.

inline foo();
hence was really
inline int foo();

etc...

This is not legal in C++ (although some compilers may accept it), nor
is it allowed in C anymore (many compilers accept it for compatibility).
 
A

Arijit

Ron Natalie said:
inline isn't a type, but it's what you're seeing is an anachronism.

It used to be legal in C to omit an explicit type if you had a
declaration that was otherwise syntactically valid. The implicit
type was int.

inline foo();
hence was really
inline int foo();

etc...

But inline is a C++ concept while omission of return type is a C concept.
inline foo(); was invalid C++ from day 1 and never was C.
How can a compiler take two concepts from two languages and combine it ?

-Arijit
 
R

Ron Natalie

But inline is a C++ concept while omission of return type is a C concept.
inline foo(); was invalid C++ from day 1 and never was C.
How can a compiler take two concepts from two languages and combine it ?
Actually, many C compilers supported inline before the C++ language
picked it up. The 1999 C standard does have inline (of course it
doesn't have implicit int).

The answer was that the code was never strictly proper in any version
of the C and C++ standards, but there's enough cross pollenation and
backwards compatibility that let people get away with that sort of
declaration.
 
M

Mike Smith

Arijit said:
But inline is a C++ concept while omission of return type is a C concept.
inline foo(); was invalid C++ from day 1 and never was C.
How can a compiler take two concepts from two languages and combine it ?

Many of your major PC C++ compilers are also C compilers - and do in
fact do just that, i.e. kinda mix-n-match C rules with C++ rules.
 
A

Arijit

Mike Smith said:
Many of your major PC C++ compilers are also C compilers - and do in
fact do just that, i.e. kinda mix-n-match C rules with C++ rules.

Actually I was thinking in the lines of grammer. While parsing, the compilers
must select either the C grammer or the C++ grammer, they can't select a hybrid.
However, as Ron said if the compilers support inline keyword in C, then they
can use C grammer and compile. No mixing is necessary.
 

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

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,518
Latest member
TobiasAxf

Latest Threads

Top