🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #23138

Lightspeed C bug?

#23138
From: Chris Christensen
Date: Tue, 22 Dec 1987 17:12
27 lines
1026 bytes
I have been having a real head-scratcher problem with Lightspeed C.

I am trying to generate random numbers from 0 to 7.

I use

#define ABS(x) (((x) < 0) ? -(x) : (x))
x = ABS(Random()) % 8;

I get random numbers from -7 to 7

I use

x = Random();
x = ABS(x);
x %= 8;

I get the desired range.

This is the define for Absolut that I have always used. Why doesn't this work?
Am I being bitten by a "one pass" compiler bug?

--------------------------------------------------------------------------------
Chris Christensen				Hewlett-Packard
(408) 553-2955 or telnet 553-2955		Design Technology Center
cnc%hpdtc@hplabs.hp.com			Santa Clara, CA
...!hplabs!hpcid!cnc
Technical Details
Message-ID: <870081@hpcilzb.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!cmcl2!rutgers!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpcea!hpcilzb!cnc

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!cmcl2!rutgers!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpcea!hpcilzb!cnc
From: cnc@hpcilzb.HP.COM (Chris Christensen)
Newsgroups: comp.sys.mac
Subject: Lightspeed C bug?
Message-ID: <870081@hpcilzb.HP.COM>
Date: 22 Dec 87 17:12:36 GMT
Organization: HP Design Tech Center - Santa Clara, CA
Lines: 27