This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Volatile constants?
- To: 97nv46 at skola dot kiruna dot se
- Subject: Re: Volatile constants?
- From: Erik Mouw <J dot A dot K dot Mouw at its dot tudelft dot nl>
- Date: Wed, 29 Mar 2000 17:30:09 +0200 (MET DST)
- Cc: gcc at gcc dot gnu dot org
- Organization: Eric conspiracy secret labs
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/