🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #602

Re: Escape from strong typing (was: swap(x,y))

#602
From: David Keppel
Date: Fri, 01 Sep 1989 19:05
41 lines
1746 bytes
karl@haddock.ima.isc.com (Karl Heuer) writes:
>[`copybit' should generate a simple move-bit instruction]
>[I wanted to write]
>	unsigned int copybit(unsigned int x) {
>		if (x & 0x10) x |= 0x40; else x &= ~0x40;
>		return (x);
>	}
>[Suggesting:]
>	typedef struct { unsigned int :4, src:1, :1, dst:1; } hack;
>	unsigned int copybit(unsigned int x) {
>		escape(x, hack).dst = escape(x, hack).src;
>	}
>[Yes, I'm aware of the portability problems.]

In cases such as this, GNU CC provides another solution: typed
asm's that take variables as arguments.  If you care, you can
even put this function in to your .h file, qualify it with
`inline', and away you go!

#ifdef __GNUC__
	unsigned int
    copybit (unsigned int x)
    {
    #ifdef __vax__
	asm ("mumble %0,%1" : "=r" (x) : "0" (x));
    #elseif defined (__machine__)
	...
    #else
	{ NEED A MACHINE TYPE! }	/* Compile-time error. */
    #endif
	return (x);
    }
#else
	unsigned int
    copybit (..) {...}
#endif

		;-D on  ( A void* warranty )  Pardo
-- 
		    pardo@cs.washington.edu
    {rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo
Technical Details
Message-ID: <9114@june.cs.washington.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!pardo
References: <MYwDEFy00WB842JEUx@andrew.cmu.edu> <8350@boring.cwi.nl> <14479@haddock.ima.isc.com> <1545@l.cc.purdue.edu> <10897@smoke.BRL.MIL> <14500@haddock.ima.isc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!pardo
From: pardo@cs.washington.edu (David Keppel)
Newsgroups: comp.lang.misc
Subject: Re: Escape from strong typing (was: swap(x,y))
Message-ID: <9114@june.cs.washington.edu>
Date: 1 Sep 89 19:05:25 GMT
References: <MYwDEFy00WB842JEUx@andrew.cmu.edu> <8350@boring.cwi.nl> <14479@haddock.ima.isc.com> <1545@l.cc.purdue.edu> <10897@smoke.BRL.MIL> <14500@haddock.ima.isc.com>
Reply-To: pardo@june.cs.washington.edu (David Keppel)
Organization: University of Washington, Computer Science, Seattle
Lines: 41