Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Use of inline function in inline function - is it allowed? (http://www.velocityreviews.com/forums/t437103-use-of-inline-function-in-inline-function-is-it-allowed.html)

TGOS 02-26-2005 01:46 PM

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


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.

--
TGOS

Jens.Toerring@physik.fu-berlin.de 02-26-2005 02:34 PM

Re: Use of inline function in inline function - is it allowed?
 
TGOS <tgos@invalid.invalid> wrote:
> 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
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de

DHOLLINGSWORTH2 02-27-2005 03:29 AM

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

"TGOS" <tgos@invalid.invalid> wrote in message
news:1109425568.decc7d5e22696623245feb600b2c888c@m eganetnews2...
>
>
> 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.
>
> --
> TGOS


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.



Kevin Bracey 02-28-2005 10:49 AM

Re: Use of inline function in inline function - is it allowed?
 
In message <1109425568.decc7d5e22696623245feb600b2c888c@megan etnews2>
TGOS <tgos@invalid.invalid> wrote:

>
>
> 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. ]

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1728 727430
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/


All times are GMT. The time now is 02:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.