This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Volatile constants?
- To: "Christian Häggström" <97nv46 at skola dot kiruna dot se>
- Subject: Re: Volatile constants?
- From: Richard Earnshaw <rearnsha at arm dot com>
- Date: Thu, 30 Mar 2000 13:21:02 +0100
- Cc: J dot A dot K dot Mouw at its dot tudelft dot nl, gcc at gcc dot gnu dot org
- Cc: rearnsha at arm dot com
- Organization: ARM Ltd.
- Reply-To: rearnsha at arm dot com
> /* Okay I forgot the parenthesis, but that was not my point */
>
> The GCC manual says "An Inline Function is As Fast As a Macro",
> but when I compile this (as C code), I got error "initializer element is not constant" on
> 's' initialization.
>
> 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);
>
> Is there any option I have to pass?
>
> >I don't get that error message. Here is what my compiler says: ...
>
> Okay you use g++. I use the c compiler.
> g++ don t generate an error (not even a warning) for this,
> but makes an constructor function, 'static_initialization_and_destruction'-something
> That is not what I want and it is NOT as fast as a macro.
>
> >I think you should upgrade to gcc-2.95.2.
> I compiled with that version, yes
>
> I ll be glad for any help
>
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.
Speed has nothing to do with it; the semantics are different.
Now if the manual said "an inline function is the SAME as a macro", then
you would have a legitimate complaint. But it doesn't, so you don't.
R.