storm@cs.mcgill.ca (Marc WANDSCHNEIDER) (03/04/91)
As far as I've been led to believe, when one doesn't exactly know what the incoming paramter in a procedure/function is, you can just do the following: procedure hooblah(var x); var y: integer absolute x; z: real absolute x; begin etc.... Using this, the parameter passed can be passed to either an integer or a real number. However, a few days ago, I ran across this in a procedure that convers a decimal number into a HEX number... Function DectoHex (i:Word): St4; {st4 is string[4] declared already} var HexStr: string[8]; b : array[1..2] of BYTE ABSOLUTE i; bt: byte; begin etc... i has already been declared as a typed variable. How is it that it is being used here as an UNTYPED variable..? Any help on this would dearly help my already overloaded brain. Thanks yea. ./*- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storm@cs.mcgill.ca McGill University It's 11pm, do YOU Marc Wandschneider Montreal, CANADA know what time it is? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ehill@ziggy.austin.ibm.com (03/05/91)
In article <1991Mar4.043821.4742@cs.mcgill.ca> storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: [Some text deleted..] > > Function DectoHex (i:Word): St4; {st4 is string[4] declared already} > var HexStr: string[8]; > b : array[1..2] of BYTE ABSOLUTE i; > bt: byte; > begin > etc... > >i has already been declared as a typed variable. How is it that it is >being used here as an UNTYPED variable..? > >Any help on this would dearly help my already overloaded brain. > >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Remainder deleted..] REPLY: This is just another form of type casting. In the case above, the programmer wanted to treat the WORD variable as an array of two bytes. Since a WORD is two bytes this allows the programmer to manipulate each byte independently. The method may be used on both typed and untyped variables. There are dangers in this type of casting. If you don't use a variable of equal or less storage place, you run the risk of wiping out some valuable data. SO, PROGRAMMER BEWARE!!! Hope that helps, Ed Hill internet: ehill@wombat.austin.ibm.com ---------------------------------------------------------------------------- DISCLAIMER: The comments above are solely those of the writer, not IBM. ----------------------------------------------------------------------------