This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Volatile constants?


On Wed, 29 Mar 2000 14:56:14 +0200, Q2hyaXN0aWFuIEjkZ2dzdHL2bQ== wrote:
> The GCC manual says "An Inline Function is As Fast As a Macro",
> but when I compile this, 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)

<nitpick>
You should define this as:

  #define abs2(x) ((x) < 0 ? (-x) : (x))

Rationale: see what happens with your version if you use abs2(2 - 3). The
extra parentesis enforce the correct operator precedence.
</nitpick>

> 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:

  erik@lumiere:/tmp >g++ -v
  Reading specs from /usr/it/packages/gcc/gcc-2.95.2/install/irix65/lib/gcc-lib/mips-sgi-irix6.5/2.95.2/specs
  gcc version 2.95.2 19991024 (release)
  erik@lumiere:/tmp >g++ -Wall -O2 -c foo.c -o foo.o
  erik@lumiere:/tmp >

I think you should upgrade to gcc-2.95.2.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]