🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

porting C++

#17
From: Bjarne Stroustrup
Date: Tue, 18 Feb 1986 14:53
38 lines
2258 bytes
> From: pallas@Navajo.ARPA (Joseph Pallas)
> Newsgroups: net.lang.c++
> Subject: Re: porting C++
> Organization: Stanford University
>
> Can anyone tell me why the compiler wants some of the more obscure stuff,
> and how I can figure it out at runtime in a C program?

Most of the alignment stuff is needed to allow the compiler to calculate
sizeofs. Consider this beauty:

	struct s { int a: 4; };
	int v[ sizeof(struct s) ];

What is the size of struct s? Well, that depends.

On some machines every struct has a minimal size so the answer is something
like sizeof(char*). On other machines the minimal space set aside for a field
is sizeof(int). On the other hand there are machines/C-compilers that use only
sizeof(char) for struct s. This is the minimum size since a char is defined
to be the smallest unit of memory that can be independently allocated. There
are also machines where sizeof(struct s)==sizeof(int), but where
	struct ss { char a : 4; };
implies sizeof(struct ss)==sizeof(char). Obscure, yes. Perverse, maybe. But
it has to be right to preserve C link-compatibility. I don't know any fully
portable way of finding all the information needed (remember this must be
done in such a way that it circumvent ``inessential'' C compiler bugs and
restrictions). Every time I think I have it, someone comes along with a C
compiler with a new twist.

C, and therefore C++, says that the type of an integer constant is int
unless the value is larger than the largest integer in which case the
type is long. Consequently a C++ compiler must know what the largest
int is. Here is one way of getting that value in C on a two's complement
machine:
	int largest = ((unsigned)~0)>>1;

	- Bjarne Stroustrup (AT&T Bell Labs, Murray Hill)
Technical Details
Message-ID: <4992@alice.uUCp>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!alice!bs

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site alice.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!alice!bs
From: bs@alice.UucP (Bjarne Stroustrup)
Newsgroups: net.lang.c++
Subject: porting C++
Message-ID: <4992@alice.uUCp>
Date: Tue, 18-Feb-86 09:53:17 EST
Article-I.D.: alice.4992
Posted: Tue Feb 18 09:53:17 1986
Date-Received: Wed, 19-Feb-86 04:28:31 EST
Organization: Bell Labs, Murray Hill
Lines: 39