🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9722

Re: Must casting destroy lvalueness?

#9722
From: Jerry Leichter
Date: Wed, 05 Nov 1986 18:35
35 lines
2235 bytes
All this has really gotten out of hand.  I've found I've wanted to use casts
as lvalues in exactly one situation:  Incrementing a pointer by an amount
that is NOT to be taken as a multiple of the size of the type pointed to.
A "common" - NONE of these are what I'd really want to call common, but I
HAVE run into them more than once - case is in a (machine dependent!) storage
allocator that wants to make sure of proper alignment.  This doesn't arise
in something like malloc, which wants a char * (void *, in ANSI C) anyway,
but in specialized applications.  For example, I need to allocate stuff out
of a large array.  The "stuff" will be of a known type - a struct whose last
element is a varying-length array - and will thus be varying in size.  The
begining of anything allocated must be on an even address.  So I have a pointer
to some big structure that I'd like to increment by 1.  Not 1*size of the
structure, but 1.  YES, THIS IS MACHINE DEPENDENT - I got tied down by such
a dependency when I cast the pointer to int to look at the bottom bit!

I can think of no particular use for casting of arbitrary lvalues, but in
situations as above, the following definition for a cast argument to op=
would be handy:

	(type)a op= b

	shall mean:

	a = (type)a op b

(except that a is only evaluated once).

Pre- and post-decrement and increment should work in the obvious way.  Note
that the type of (type)a op= b (and of ++(type)a, etc.) is the type of a,
NOT the type being cast to.

I can think of no real uses for this construct where "op" is anything but
"+" or "-".
							-- Jerry
Technical Details
Message-ID: <3998@yale-celray.yale.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!cmcl2!yale!leichter
References: <4617@brl-smoke.ARPA> <657@dg_rtp.UUCP> <61@cartan.Berkeley.EDU> <667@dg_rtp.UUCP>

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!cmcl2!yale!leichter
From: leichter@yale.UUCP (Jerry Leichter)
Newsgroups: net.lang.c
Subject: Re: Must casting destroy lvalueness?
Message-ID: <3998@yale-celray.yale.UUCP>
Date: Wed, 5-Nov-86 13:35:34 EST
Article-I.D.: yale-cel.3998
Posted: Wed Nov  5 13:35:34 1986
Date-Received: Wed, 5-Nov-86 22:33:33 EST
References: <4617@brl-smoke.ARPA> <657@dg_rtp.UUCP> <61@cartan.Berkeley.EDU> <667@dg_rtp.UUCP>
Reply-To: leichter@yale-celray.UUCP (Jerry Leichter)
Organization: Yale University, New Haven, CT
Lines: 35