delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/21/03:06:33.1

Message-ID: <F02EDE79D030D11192BA006008136ED11A61CE@pamela.x3m.se>
From: Ztream <Ztream AT x3m DOT se>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>
Subject: RE: ? strange problem
Date: Mon, 21 Dec 1998 09:02:29 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2232.9)
Reply-To: djgpp AT delorie DOT com

> -----Original Message-----
> From:	twidler444 AT aol DOT com [SMTP:twidler444 AT aol DOT com]
> Sent:	Monday, December 21, 1998 7:19 AM
> To:	djgpp AT delorie DOT com
> Subject:	Re: ? strange problem
> 
	>Hello
	>   I couldn't find the earlier posting, But I think I know what you
are talking
	>about, and how to fix it.

	>does your code look something like this?

	>typedef struct TEST
	>{
	>int x,y;
	>}TEST;
	>
	>TEST it;
	>
	>int main()
	>{
	>TEST temp;
	>
	>temp=it;
	>temp.x=10;
	>temp.y=50;
	>
	>// then here is were you find out that it.x isnt 10
	>}

The reason it.x isn't 10 is because it is simply never set to 10. temp is
not a pointer. temp=it copies all member fields from "it" to temp, but temp
is still a completely independent variable; what you do to temp does not and
should not affect "it" in any way.

I guess that what you mean to do is something like the following: 

int main()
{
TEST *temp;

temp=&it;
temp->x=10;
temp->y=50;
}

This correctly alters "it" as you are altering temp->x.

	>I found that in DJGPP(and other free compilers) that you can only
read from
	>temp.x and not write.

I feel rather confident that the above should not work under *any* compiler
(*that* would be a bug). Please correct me if I'm wrong, but I tested both
your original code and my altered code, and they both confirmed what I'm
saying.

Or, perhaps you just made an error in the comment on the last line, actually
meaning temp.x ;) This does, however, work as expected, and the rest of the
mail seems to confirm that you do mean what you typed.

Hope this is of help :)

/ Z

---------------------------------------------------------------------------
Ztream / 1x4x9 - "The white dwarf"
ztream AT x3m DOT se \ www.highrad.x3m.se/Ztream
Free your mind.

- Raw text -


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