Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!gatech!bloom-beacon!oberon!sdcrdcf!psivax!csun!abcscnuk From: abcscnuk@csun.UUCP (Naoto Kimura) Newsgroups: comp.lang.pascal Subject: Re: Pointer problem ? Message-ID: <698@csun.UUCP> Date: Sun, 26-Jul-87 02:35:25 EDT Article-I.D.: csun.698 Posted: Sun Jul 26 02:35:25 1987 Date-Received: Wed, 29-Jul-87 07:00:38 EDT References: <254@askja.UUCP> Reply-To: abcscnuk@csun.UUCP (Naoto Kimura) Distribution: world Organization: California State University, Northridge Lines: 60 In article <254@askja.UUCP> frisk@askja.UUCP (Fridrik Skulason) writes: >Can anyone tell me if this program fragment is supposed to compile or not. >Turbo Pascal refuses to compile it, but VAX/VMS Pascal does. > >program t; >type > p1 = ^p1; > p2 = ^p1; > p3 = ^p2; > >var p : p1; > r : p3; >begin > p := r; >end. >-- >Fridrik Skulason Univ. of Iceland, Computing Center > UUCP ...mcvax!hafro!askja!frisk BIX frisk > > "This line intentionally left blank" The variables "p" and "r" are of different types. "P" is a pointer to an object of type "p1" while "r" is a a pointer to an object of type "p2", which is a pointer to an object of type "p1." Even though "p" and "r" are both pointer to something, they won't be the same, because they point to different types of objects ( ^p1 <> ^^p1 ). If you want to get pointers to an arbitrary data object, you'll have to fiddle around with variant record types: -- program foo; type foo : record case 1..5 of 1 :(intptr : ^integer); 2 :(charptr : ^char); 3 :(realptr : ^real); 4 :(boolptr : ^boolean); 5 :(fooptr : ^foo) end; var p, r : foo; s : ^char; begin new(s); s^ := 'a'; p.charptr := s; p.intptr := q.intptr; end. -- There is a problem with using things like this, alignment, since char, boolean, real, integer, etc. will have different storage requirements and restrictions, especially on word addressed machines. -- //-n-\\ Naoto Kimura _____---=======---_____ (csun!abcscnuk) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!