🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #512

Re: Semi constant expressions

#512
From: Mark Brader
Date: Thu, 31 Aug 1989 17:56
29 lines
1579 bytes
>	x << (100000000L)

Unlike the 0*x and 0/x examples, this one is explicitly undefined behavior
(assuming that x is of an integral type less than 100000000 bits wide!).

See 3.3.7:
	If the value of the right operand is negative or is greater
	than or equal to the width in bits of the promoted left
	operand, the behavior is undefined.

The reason for this restriction is to simplify implementation on computers
where the shift instruction's amount-to-shift field is only lg2(wordsize)
bits long -- that is, is only 5 bits if ints are 32 bits, for example --
or where only that many bits are actually examined, or where a software
shift is done and has similar restrictions.

By the way, the L on the right operand has no effect.  In the proposed
standard the type of the result of << is the promoted type of the left
operand, so it doesn't matter whether the right operand is int or long,
and the plain constant 100000000 would be one or the other depending on the
size of ints.


-- 
Mark Brader		    "...most mistakes are made the last thing before
SoftQuad Inc., Toronto	        you go to bed.  So go to bed before you do
utzoo!sq!msb, msb@sq.com	the last thing."	-- David Jacques Way

This article is in the public domain.
Technical Details
Message-ID: <1989Aug31.175652.29643@sq.sq.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utfyzx!sq!msb
References: <1237@gmdzi.UUCP>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utfyzx!sq!msb
From: msb@sq.sq.com (Mark Brader)
Subject: Re: Semi constant expressions
Message-ID: <1989Aug31.175652.29643@sq.sq.com>
Reply-To: msb@sq.com (Mark Brader)
Organization: SoftQuad Inc., Toronto
References: <1237@gmdzi.UUCP>
Date: Thu, 31 Aug 89 17:56:52 GMT