Re: Definitions of Typecast etc.

rkrayhawk@aol.com (RKRayhawk)
23 Feb 2001 00:04:26 -0500

          From comp.compilers

Related articles
Definitions of Typecast etc. vbdis@aol.com (2001-02-04)
Re: Definitions of Typecast etc. rkrayhawk@aol.com (2001-02-15)
Re: Definitions of Typecast etc. vbdis@aol.com (2001-02-17)
Re: Definitions of Typecast etc. rkrayhawk@aol.com (2001-02-23)
Re: Definitions of Typecast etc. joachim_d@gmx.de (Joachim Durchholz) (2001-02-25)
| List of all articles for this month |

From: rkrayhawk@aol.com (RKRayhawk)
Newsgroups: comp.compilers
Date: 23 Feb 2001 00:04:26 -0500
Organization: AOL http://www.aol.com
References: 01-02-086
Keywords: practice
Posted-Date: 23 Feb 2001 00:04:25 EST

vbdis@aol.com (VBDis)
<< ... type conversion and type cast
differ in the /object/ of the cast. A type cast, for itself, will /never/
modify the information on which it is applied, it only changes the
/interpretation/ of it's argument.
A type conversion instead can (at least)
modify the /stored information/, on which it is applied.


Is that assumption correct?
>>


LIke all of your posts, that is well said. For lurkers new to the issue of
casting and converting, lets add the pedantic reminder that we always have a
choice of converting data in place (source location and destination loaction
are the same), versus converting while moving (source location a destination
location differ).


This applies to the global use of the term 'convert', as in 'convert the master
file', as well as to the slightly more technical use of the term describing
data conversion while moving from memory location to memory location, of
between memory and the registers of the CPU.


Loading a byte with sign extension into a register with more than eight bits,
actually converts the data. Loading a byte while clearing the upper bits of a
register with more than eight bits, actually converts the data. (In some
architectures these conversions can be done with one instruction, sometimes it
takes a couple).


On occassion moving a multi-byte data item onto a parallel port that handles
only one byte at a time can involve (endian) conversion. Moving a byte of data
into a port that sends it out as eight bits serially, actually converts it
(even if no parity and no stop/start bits where agglutinated).


Pack instructions on mainframes convert data. And the very distinct pack
instrution on Itanium chips convert data.


With technical work it is generally rare to convert in-place; source and
destination are usually different. We usually see in-place conversion when the
machine (hardware or software) will not assist us in natural conversions.


  temp_dest = source_data;
  temp_dest = we_had_to_do_it_manually(temp_dest);
  destination_data = temp_dest;


where the last statement, just to tie it all together, usually requires a type
cast.


  destination_data = (DESTINATION_TYPE) temp_dest;


In COBOL you can do a REDEFINE that accomplishes type casting. In C you can
use unions. In assembler you can use ORG (origin), to remap data item
collections according to different type specifications.


Hope that is not too verbose.




Robert Rayhawk
rayhawk@alum.calberkeley.org


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.