delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/18/07:15:25

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: assigning the correct adress?
Date: Tue, 17 Feb 1998 18:43:02 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 40
Message-ID: <34EA2086.1595@cs.com>
References: <34e9a8df DOT 2317141 AT news DOT rug DOT nl>
NNTP-Posting-Host: ppp213.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Donnie Roos wrote:
> 
> In my program i have a variable of word size (unsigned short)
> and two pointers which point to the two bytes of this word.
> 
> word TMP;
> byte *ptr_TMP_l, *ptr_TMP_h;
> 
> In my code i try to assign it in the following way.
> It needs a cast to increase the adress by 1 byte instead of a word.
> 
> ptr_TMP_l = & (byte) reg_TMP;
> ptr_TMP_h = & (byte) reg_TMP + 1;
> 
> When compiling my source from RHIDE (default options) i get the
> message: invalid lvalue in unary `&'

Of course this won't work.  It is logically impossible to take the
address of the result of a typecast; the value this represents does not
exist in any form that would be useful to your program.  What you need
to do is figure out the address first and then typecast it to the proper
pointer type, as shown below:

ptr_TMP_l = (byte *) (&reg_TMP);
ptr_TMP_h = ( (byte *) (&reg_TMP) ) + 1;

I've added parentheses for clarity, but the order of operations doesn't
require them.

Hope this helps.

-- 
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>  UIN# 7406319

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? C++>$ U@>++$ p>+ L>++ E>++ W++ N++ o+>++ K? w(---)
O- M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+(++) tv+() b+++ DI++ D++ G>++
e(*)>++++ h!() !r !y+()
------END GEEK CODE BLOCK------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019