www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/03/16:59:34

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using Pointers ?
Date: Mon, 03 Feb 1997 15:07:37 -0800
Organization: Two pounds of chaos and a pinch of salt
Lines: 32
Message-ID: <32F66FB9.1FC2@cs.com>
References: <32F662F9 DOT 1F3B AT post DOT comstar DOT ru>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp208.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Dim Zegebart wrote:
> 
> //FOO3
> int foo3(TMyType *ptr)
> {
>  //TMyType has fields fld1 and fld2 both int
>  int i,fld1=ptr->fld1,fld2=&ptr->fld2;
                             ^
I assume you forgot to take out that address operator...

>  for (i=0;i<100000;i++)
>   { fld1++; //here may be any expression. ++ just for example
>     fld2--;
>   }
>  ptr->fld1=fld1;
>  ptr->fld2=fld2
>  return(1);
> }

Sorry; I replied too soon.  This last function will not work the way you
want it to.  By assigning ptr->fld1 to fld1, you are making a _copy_ of
that field.  Then when you modify the copy, the original is unchanged. 
This function will probably be faster than the first two (for obvious
reasons), but it won't work.  :)

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
| Call me for your free AOL disk!  |   http://www.cs.com/fighteer   |
|  Chain letters, work-at-home schemes, free long distance, etc.,   |
|    are ILLEGAL!  Keep the Internet litter-free... don't SPAM.     |
---------------------------------------------------------------------

- Raw text -


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