home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Why should POINTERS be so damn hard to understand ?
- Message-ID: <1992Aug27.161245.10339@taumet.com>
- Organization: TauMetric Corporation
- References: <9208251159.AA04122@ult4> <1992Aug26.124652.9509@alw.nih.gov> <1992Aug26.183054.14146@newshub.ccs.yorku.ca> <l9nl34INNhln@almaak.usc.edu> <25233@castle.ed.ac.uk>
- Date: Thu, 27 Aug 1992 16:12:45 GMT
- Lines: 42
-
- chas@castle.ed.ac.uk (C Spencer) writes:
-
-
- >Why does a pointer need to know what it's pointing to? Surely it's just
- >an address - if there was only one kind of pointer, there wouldn't be so
- >much to learn, and be confused by.
-
- This has to do with mixing levels of abstraction, and how you choose
- to look at programming.
-
- Case 1: Programming is a method of causing a particular machine
- to behave in a particular way.
- You don't care about types, and you probably want a typeless langauge.
- The language is just a convenient shorthand for machine instructions,
- maybe with some control abstractions (if, loop, case). This is quite
- suitable for small embedded computers -- device controllers, for example.
-
- Case 2: Programming is a method of expressing an algorithm or
- procedure for communication to humans and machines.
- You want an abstract description, machine-independent, of the algorithm
- or process. You want types in the language, so that it can be made
- plain what the interactions are intended to be. This improves
- communication among humans. Stronger typing also leads to more help
- from the compiler in finding many kinds of simple errors in writing
- the code -- errors which would be much harder to find at run-time.
-
- To answer the question more directly:
-
- 1. When you read code and see that 's' points to a string, 'q' to a
- floating-point number, 'p' to a structured object, isn't that more
- help in understanding the program than when you have a bunch of
- pointers and you don't know what they are pointing to?
-
- 2. A pointer is not necessarily just an address. On many machines
- the size of and the interpretation of the bits in a pointer depend
- on what it points to. The type of the object pointed to is embedded,
- at least in part, in the pointer. The machine can detect at runtime
- misuse of pointers.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-