🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #301

(or does it?)

#301
From: Bjarne Stroustrup
Date: Sat, 06 Sep 1986 01:13
44 lines
1906 bytes
> From: stephen@comp.lancs.ac.uk (Stephen J. Muir)
> Newsgroups: net.lang.c++
> Subject: C++ doesn't output unsigned correctly.
> Organization: Department of Computing at Lancaster University, UK.

> This program incorrectly prints minus one:
> 
> # include <stream.h>
> 
> main ()
> {	unsigned x = -1;
> 	cout << x << "\n";
> }
> 
> C++ version 1.1, BSD 4.2, DEC VAX-11/750.

``that is not a bug; it is a feature''. To get the desired answer 4294967295
you must use some kind of formatting function; for example:

	cout << form("%u\n",x);

Maybe there ought to be a separate function ``unsig()'' like the ``oct()''
and ``hex()'' functions, but currently there is not.

In general: the stream library needs work - and will receive it.

The general problem of which this problem with unsigned is a symptom is that
C++'s resolution mechanism for overloaded functions cannot distinguish an
``unsigned'' from an ``int''. For example, if one could declare

	overload f(unsigned), f(int);

which function would f(-1) call? which one would f(1) call? why?

I am not convinced that there are no answers, but currently the declaration
of f above is illegal.

There are other type differences that the overloading mechanism cannot distinguish:

char, short, int:	there are no rvalues of type char or short
float, double:		there are no rvalues of type float
			(will be fixed when ANSI C gets accepted)
T, const T:		can be a problem
T, T&:
Technical Details
Message-ID: <6021@alice.uUCp>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!burl!ulysses!allegra!alice!bs

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!burl!ulysses!allegra!alice!bs
From: bs@alice.UucP (Bjarne Stroustrup)
Newsgroups: net.lang.c++
Subject: (or does it?)
Message-ID: <6021@alice.uUCp>
Date: Fri, 5-Sep-86 21:13:10 EDT
Article-I.D.: alice.6021
Posted: Fri Sep  5 21:13:10 1986
Date-Received: Sat, 6-Sep-86 20:17:15 EDT
Organization: Bell Labs, Murray Hill
Lines: 44