Use of inline function in inline function - is it allowed?

T

TGOS

Is it allowed and safe with most compiler, to use inline within an
inline function?

E.g.

static inline void
myFunc()
{
...
}


static inline void
myFunc2()
{
...
myFunc();
...
}


static inline void
myFunc3()
{
...
myFunc();
...
}


And now I'm calling myFunc(), myFunc2() and myFunc3() at different
occassions all over the rest of code. Is that legal?

Because I had a strange bug in my program and after removing the inline
of the three functions, the bug was gone. Coincident? A bug in the
compiler? I don't know for sure.

So I thought, lets first ask some experts if inlining in inlined
functions is considered a safe operation.
 
J

Jens.Toerring

TGOS said:
Is it allowed and safe with most compiler, to use inline within an
inline function?

If you define what you take to be "most" compilers it would be easier
to answer;-) The C89 standard doesn't mention 'inline', but C99 now
has it. That probably means that a lot of compilers already had
'inline' and it therefor became included into the standard. But as
long as the compiler is only C89 and not C99 compliant it don't need
to have it. For such compilers you are going to need a line like

#defined inline

to make the compiler "overlook" it. But you will easily see if you
need that because the compiler should complain loudly if it doesn't
know what 'inline' is.
Because I had a strange bug in my program and after removing the inline
of the three functions, the bug was gone. Coincident? A bug in the
compiler? I don't know for sure.

That may only be a side effect of using 'inline' - my first guess
would be that you have some memory corrution in your program and,
since the layout of the program might be quite different with in-
lined functions, switching inlining on just exposes the bug.

Regards, Jens
 
D

DHOLLINGSWORTH2

TGOS said:
Is it allowed and safe with most compiler, to use inline within an
inline function?

E.g.

static inline void
myFunc()
{
...
}


static inline void
myFunc2()
{
...
myFunc();
...
}


static inline void
myFunc3()
{
...
myFunc();
...
}


And now I'm calling myFunc(), myFunc2() and myFunc3() at different
occassions all over the rest of code. Is that legal?

Because I had a strange bug in my program and after removing the inline
of the three functions, the bug was gone. Coincident? A bug in the
compiler? I don't know for sure.

So I thought, lets first ask some experts if inlining in inlined
functions is considered a safe operation.

Declaring a function as inline, should only change the calling convention
used, as such anyplace you can call a function you should be able to call an
inline function.

I am not aware of any compilers that do allow one level, but not two.
Unfortunately I am not aware of all the compilers out there.

I'd say that if your compiler has a problem with it, dump it, and find a new
compiler.
 
K

Kevin Bracey

In message <1109425568.decc7d5e22696623245feb600b2c888c@meganetnews2>
TGOS said:
Is it allowed and safe with most compiler, to use inline within an
inline function?

And now I'm calling myFunc(), myFunc2() and myFunc3() at different
occassions all over the rest of code. Is that legal?

Absolutely. "inline" doesn't change the semantics of calls at all. Indeed, an
inline function is allowed to call itself recursively.

Exactly what the compiler does in these cases, and how efficient it is, are
an implementation matter.
Because I had a strange bug in my program and after removing the inline
of the three functions, the bug was gone. Coincident? A bug in the
compiler? I don't know for sure.

Sounds like a compiler bug. "inline" should not normally affect the
observable behaviour. There might be some edge cases if you have different
inline and out-of-line definitions (which is unusual but permitted).

[ My responses refer to C99 - you may be using a pre-C99 compiler with its
own inline semantics. ]
 

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,772
Messages
2,569,589
Members
45,100
Latest member
MelodeeFaj
Top