[prev in list] [next in list] [prev in thread] [next in thread]
List: gcc
Subject: Re: Volatile constants?
From: Richard Earnshaw <rearnsha () arm ! com>
Date: 2000-03-31 11:16:09
[Download RAW message or body]
> inline int abs1(int x) {
> return x<0 ? -x : x;
> }
> #define abs2(x) ((x)<0 ? -(x) : x)
>
> int r = abs1(-7);
> int s = abs2(-7);
>
> >An inline function is NOT a macro, it's still a function. You can't use a
> >function as an initializer for a static extent variable in C.
>
> OK, this is not valid in ANSI C
> In C++, however, this is valid.
> Now, take a look at the assembly output (x86,regparm)
>
[...]
> Why is 'r' not handled as 's'?
> This is slower and occupies more memory.
>
Because even in C++ you have still specified it as a constructor function,
not a constant expression. All this means is that the your inline
function will get inlined into your constructors rather than left as a
stand-alone function that is called by them (try taking the "inline" out
and see how it changes your assembly output).
R.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic