🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.v7
Article #62

overflow in C revisited

#62
From: utzoohenry
Date: Tue, 04 May 1982 22:02
26 lines
852 bytes
Very entertaining things can happen with integer overflow in C.  This
isn't really a bug, except that (as reported some months ago) the
manual should say the effects of overflow are "undefined" instead of
saying that it is "ignored".  Consider the following:

-----
/*
 * Arithmetic in the presence of overflow is context-dependent in
 * very strange ways.
 */

unsigned int compile = (56*1024)/64;

main()
{
	printf("%u == %u\n", compile, (56*1024)/64);
	printf("%u == %u == %u (!!)\n", compile, 57734/64, (56*1024)/64);
}
-----

Can you guess what this prints?  Like this:

	65408 == 65408
	65408 == 0 == 902 (!!)

Yes, friends, it's context-dependent!
Technical Details
Message-ID: <anews.Autzoo.1633>
Path: arc1-ca.pugleaf.net!utzoo!henry

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!henry
From: utzoo!henry
Newsgroups: net.bugs.v7
Subject: overflow in C revisited
Date: Tue, 04 May 1982 22:02:15 +0000
Message-ID: <anews.Autzoo.1633>