Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!amdahl!uunet!sco!seanf From: seanf@sco.COM (Sean Fagan) Newsgroups: comp.lang.fortran Subject: Re: Data types _without_ pointers Message-ID: <1346@scolex> Date: 26 Sep 88 00:27:40 GMT References: <1580@ficc.uu.net> <4096@lanl.gov> Reply-To: seanf@sco.COM (Sean Fagan) Organization: The Santa Cruz Operation, Inc. Lines: 48 In article <4096@lanl.gov> jlg@lanl.gov (Jim Giles) writes: >How about (in Fortran-like syntax): > type dlink > integer data > dlink :: next, prev !recursive data declaration > end type dlink > dlink :: p, q > q%next = p !Fortran 8x uses % for the structure ref > p%prev%next = q !I know! I don't like % either > q%prev = p%prev > p%prev = q >No pointers! Only variables of type 'dlink'. The advantage is that >type checking will prevent me from assigning any address other that >another variable of type 'dlink' to any of the links. With pointers, >type checking is not performed (if it is, then some of the really useful >things that pointers can do are lost) - I am stuck with the possibility >of a link in my list pointing off into left field. I only want _that_ >to be possible if I really might want to point into left field. Um, to paraphrase, "a pointer by any other name would still point as sweet" (I'm a programmer, not a muse). Just because it doesn't look like a pointer doesn't mean it's *not* a pointer (and if it isn't, it is not useful in the above example). Pascal won't let you do anything other than what you're doing above. In fact, you could, probably, get rid of the '^' operator in Pascal, and you would have something like the above FORTRAN 8x code (except you would use '.' instead of '%'). You're right, over typechecked pointers are not as useful as non-typechecked pointers. Witness Pascal vs. C. However, most C compilers will warn about pointers being assigned to or from arbitrary objects (MSC will, for example, complain about malloc() being assinge to a struct X * without a type-cast). Also, in an earier posting, Jim complained about a lack of a standard for C. There is one, and has been one for quite a while: the White Book (aka the Bible, the Old Testament, K&R, and, of course, "The C Programming Language"). As far as I've been able to tell, any code that conforms to what they describe is portable to all C compilers anywhere (8086's, Pr0mes, Cybers, 3B's, Suns, etc.). It's just not as useful as going outside of the standard is. And, sad to say, FORTRAN has that same problem. In how many ways does VMS FORTRAN deviate from the standard F77? How about CDC NOS FORTRAN 5? Cray CFT? It's very easy to write portable code, and it's very easy to write useful code. It's just difficult, at times, to make the two intersect. -- Sean Eric Fagan | "ld runs like a turtle out of antartica" seanf@sco.UUCP | Steven Ryan (smryan@garth.UUCP) (408) 458-1422 | Any opinions expressed are my own, not my employers'.