Thread View: comp.lang.misc
3 messages
3 total messages
Started by Darren New
Wed, 16 Dec 1992 16:48
Re: Safety. Was: Re: Pointers
Author: Darren New
Date: Wed, 16 Dec 1992 16:48
Date: Wed, 16 Dec 1992 16:48
33 lines
1664 bytes
1664 bytes
I have never seen iasf before.
If memory serves, the body of iasf was posted in the same line where it
was used. Basically, an inlined-function version of the union punning.
> But I am more interested in this for variables than for constants,
> although it is often needed at the present time for constants.
It would certainly work for variables.
> use_double(c,d)
> where, for example, c and d would be 32-bit objects and double is 64-bit.
This is a trivial modification, using a union with two 32-bit objects
overlapping one 64-bit object.
However, C cannot choose different functions based on that their value
is returned as. What should it do if you say
process(use_double(c,d))
and you haven't declared what types "process" uses returns. It's a tiny
amount of work to use different functions depending on what you want to
pass and what you want back, compared to actually getting it to work.
-- Darren (can't believe I'm getting pulled into this again) New.
Darren New, MTS <dnew@thumper.bellcore.com> (MIME compliant)
445 South St/MRE 2E-279/Morristown NJ 07960 USA/(201)829-4833
Delivery of Electronic Multimedia over Networks (DEMON)
Also, formal description techniques, programming languages
``Sometimes, you just have to bite the silver bullet.''
Re: Safety. Was: Re: Pointers
Author: Herman Rubin
Date: Wed, 16 Dec 1992 17:39
Date: Wed, 16 Dec 1992 17:39
31 lines
1818 bytes
1818 bytes
In article <1992Dec16.164821.19079@walter.bellcore.com> dnew@thumper.bellcore.com (Darren New) writes:
.................
>> use_double(c,d)
>> where, for example, c and d would be 32-bit objects and double is 64-bit.
>This is a trivial modification, using a union with two 32-bit objects
>overlapping one 64-bit object.
>However, C cannot choose different functions based on that their value
>is returned as. What should it do if you say
>process(use_double(c,d))
>and you haven't declared what types "process" uses returns. It's a tiny
>amount of work to use different functions depending on what you want to
>pass and what you want back, compared to actually getting it to work.
My idea about "use" is much simpler. The expression use_double(...), as
I intend it, means that the bit pattern, or concatenated bit pattern,
described in the parentheses is to be now used as a double number in
any application. Therefore, in process(use_double(...)), process just
assumes that what is presented to it is a double, just as the cast to
double declares that the result is double.
--
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
Phone: (317)494-6054
hrubin@snap.stat.purdue.edu (Internet, bitnet)
{purdue,pur-ee}!snap.stat!hrubin(UUCP)
Re: Safety. Was: Re: Pointers
Author: Fergus James HENDERSON
Date: Mon, 21 Dec 1992 20:41
Date: Mon, 21 Dec 1992 20:41
33 lines
1481 bytes
1481 bytes
hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
>The expression use_double(...), as
>I intend it, means that the bit pattern, or concatenated bit pattern,
>described in the parentheses is to be now used as a double number in
>any application. Therefore, in process(use_double(...)), process just
>assumes that what is presented to it is a double, just as the cast to
>double declares that the result is double.
I don't know why I bother, but here it is anyway...
In Gnu C:
#define use_double(var) ({ \
union { typeof(var) old; double new; } tmp; \
tmp.old = var; \
tmp.new \
})
In C++:
template<class T>
double use_double(T var) {
union { T old; double new; } tmp;
tmp.old = var;
return tmp.new
}
Satisfied, Mr. Rubin?
--
Fergus Henderson fjh@munta.cs.mu.OZ.AU
This .signature virus is a self-referential statement that is true - but
you will only be able to consistently believe it if you copy it to your own
.signature file!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads