Article View: comp.std.c
Article #3452Re: (no subject) [cast expression as an lva
From: Dik T. Winter
Date: Wed, 11 Oct 1995 10:34
Date: Wed, 11 Oct 1995 10:34
25 lines
1609 bytes
1609 bytes
In article <45fgea$d8j@yage.tembel.org> shields@tembel.org (Michael Shields) writes: > In article <45ef3f$n8u@engnews2.Eng.Sun.COM>, > Steve Clamage <clamage@Eng.Sun.COM> wrote: > > What's interesting is that you can get the same effect with valid code > > that should generate the same object code as the invalid original. > > For example, instead of > > ((char*)src)++; > > you can write > > (*(char**)(&src))++; > > I don't claim this code is more readable, but you could encapsulate the > > ugliness in a macro. For example: > > #define increment_as(ptr, T) ((*(T*)(&ptr))++) > > increment_as(src, char*); > > If it is always possible, why not just legalize the first syntax? Although legal it does not necessarily work as intended! Suppose I have a pointer to int on a machine where int and char pointers have different format, what does: (*(char**)(&src))++; do? For instance, on the Cray the resulting value is the same as the value before the operation. -- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098 home: bovenover 215, 1025 jn amsterdam, nederland; e-mail: dik@cwi.nl
Technical Details
Message-ID:
<DGA5Cs.u4@cwi.nl>Path:
arc1-ca.pugleaf.net!cwi.nl!dikReferences:
<45e68p$t78@inferno.mpx.com.au> <45ef3f$n8u@engnews2.Eng.Sun.COM> <45fgea$d8j@yage.tembel.org>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c,comp.lang.c,comp.unix.solaris Path: arc1-ca.pugleaf.net!cwi.nl!dik From: dik@cwi.nl (Dik T. Winter) Subject: Re: (no subject) [cast expression as an lva Message-ID: <DGA5Cs.u4@cwi.nl> Sender: news@cwi.nl (The Daily Dross) Nntp-Posting-Host: chrysant.cwi.nl Organization: CWI, Amsterdam References: <45e68p$t78@inferno.mpx.com.au> <45ef3f$n8u@engnews2.Eng.Sun.COM> <45fgea$d8j@yage.tembel.org> Date: Wed, 11 Oct 1995 10:34:04 GMT