🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.modula2
4 messages
4 total messages Started by Soo Fighter Thu, 29 Feb 1996 23:34
pointers
#3326
Author: Soo Fighter
Date: Thu, 29 Feb 1996 23:34
5 lines
609 bytes
I have a quick question: are two pointers to two variables (which may or 
may not be of the same type) not interassignable and intercomparable?
If they are, why?

Thanks in advance.
Re: pointers
#3328
Author: Bill Seurer
Date: Fri, 01 Mar 1996 15:12
10 lines
879 bytes
In article <Pine.SOL.3.91.960229172245.1613A-100000@icarus.cc.uic.edu>, Soo Fighter <wsoo1@icarus.uic.edu> writes:
|> I have a quick question: are two pointers to two variables (which may or 
|> may not be of the same type) not interassignable and intercomparable?

They are neither.

-- 

- Bill Seurer     ID Tools and Compiler Development      IBM Rochester, MN
  Business: BillSeurer@vnet.ibm.com               Home: BillSeurer@aol.com
Re: pointers
#3329
Author: Bill Seurer
Date: Fri, 01 Mar 1996 15:17
15 lines
1106 bytes
In article <4h7440$2jcg@ausnews.austin.ibm.com>, seurer@nordruth.rchland.ibm.com (Bill Seurer) writes:
|> In article <Pine.SOL.3.91.960229172245.1613A-100000@icarus.cc.uic.edu>, Soo Fighter <wsoo1@icarus.uic.edu> writes:
|> |> I have a quick question: are two pointers to two variables (which may or 
|> |> may not be of the same type) not interassignable and intercomparable?
|> 
|> They are neither.

(hit send too soon)

...neither if they are not of the same type.

-- 

- Bill Seurer     ID Tools and Compiler Development      IBM Rochester, MN
  Business: BillSeurer@vnet.ibm.com               Home: BillSeurer@aol.com
Re: pointers
#3334
Author: Jeffrey E Stoner
Date: Mon, 04 Mar 1996 05:24
39 lines
2129 bytes
Soo Fighter (wsoo1@icarus.uic.edu) wrote:
: I have a quick question: are two pointers to two variables (which may or 
: may not be of the same type) not interassignable and intercomparable?
: If they are, why?

Pointers are just addresses.  They point to one particular place in memory.
When you specify a type for a pointer (*POINTER TO INTEGER*) you also
indicate the size of the address space.  
This is a round about way of saying no.  The why can be easily seen with
an example:

FirstVar : POINTER TO INTEGER;
SecondVar : POINTER TO REAL;

For this example, an integer will be 2 bytes and a real will be 4 bytes in 
IEEE standard format.

When you dereference FirstVar, you get 2 bytes of information.  When you
dereference SecondVar, you get 4.  If you execute this statement:
SecondVar := FirstVar;
SecondVar still dereferences 4 bytes.  The first 2 bytes will be your integer,
but the second 2 will be who knows what.  In effect, when you dereference
SecondVar, you'll get garbage.  This gets uglier when to store values in
SecondVar because you'll overwrite whatever was in those last 2 bytes.  
What was there could be instruction code or another variable.  You've
just trashed your memory.  Pretty bad, eh?

If FirstVar and SecondVar are of the same type, there's no problem because
they're the same "size."  Most compilers won't (shouldn't) let you 
assign a pointer to another of a different type without a type-cast.  

Simple, eh?  

Jeff

-- 
   *  internet-->  jesst63+@pitt.edu             * This space reserved  *
   *  http://www.pitt.edu/~jesst63               * for something much   *
   * "I am outcast, unclean." - Thomas Covenant  * better to come along *
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads