From: micja@ida.liu.se (Michael Jansson)
Subject: Re: What is (APTR) ?
Originator: micja@obel30
Organization: Department of Computer Science, University of Linkoping
Date: Tue, 15 Sep 1992 14:17:58 GMT


In article <1641@lysator.liu.se>, boberg@lysator.liu.se (Stefan Boberg) writes:
> micja@ida.liu.se (Michael Jansson) writes:
> > boberg@lysator.liu.se (Stefan Boberg) writes:
> 
> >>   Excerpt from `exec/types.h' :
> >> 
> >>   /*  WARNING: APTR was redefined for the V36 Includes!  APTR is a   */
> >>  /*  32-Bit Absolute Memory Pointer.  C pointer math will not       */
> >> /*  operate on APTR --  use "ULONG *" instead.                     */
> >>                             ^^^^^^^^^
> >> 
> >>   BTW: Why isn't this "UBYTE *" ?? Why on earth would anyone want ULONG
> >> pointer arithmetic?
> 
> >Have you ever used Tags? Process a file like Font:CGTimes.otag and you will
> >find several reasons for doing pointer maths (trust me) on ULONG:s.
> 
>   Sure, but when working with tags you work with TagItem structures and
> the corresponding utility.library functions to obtain the taglist entries.
> You should never directly address a TagItem list by doing pointer
> arithmetic on the taglist pointer.

Yes, this is typically true (and it should be). There are exceptions however,
such as when processing the OT_Indirect bit flag in diskfont tag files. This does
not have anything to do with APTR's though - it simple illustrates that you do
need to long word pointer arithmetics some times. More typical examples are when
you have to do long word aligned pointer arithmetic.

> 
>   My point was that since 680x0 memory is built up from bytes, the
> most natural pointer type would be `char *' (or UBYTE *, to use CBM 
> terminology).

Well, the Motorola 68k family does actually recognise data as bits, *then* bytes,
words and long words.  So the "natural" pointer type would be to bits then,
right!? :-).

All jokes aside - An APTR is a pointer to a *typeless* memory chunk. You can not
assume that the referred memory will be accessed as bytes or long words. It
*must* follow the alignment rules that are the most restrictive, i.e. be long
word aligned! Use STRPTR or whatever if you want to point out data of some known
type.

> 
>   Anyway, I really don't care since I never use the types defined in 
> <exec/types.h> ...

Then consider the use of (void *) and (char *). The first is a generic pointer
which can point to data of any type, the latter can only point out bytes. They
can not be used interchangeably.

APTR`s (or void *) are extremely useful when applying software engineering
techniques such as "data hiding" and "polymorphism", where a pointer may referred
to data of an unknown type.

> 
> >     Michael Jansson	  mij@IDA.LIU.SE, uunet!liuida!mij, mij@SELIUI51.BITNET
> --
> Stefan Boberg - AP & EE student at Linkoping Institute of Technology, Sweden
>  Author of LhA, ArjA and LhArcA. Co-author of Alien Breed, Project X, Full
>   Contact and Miami Chase.
>     EMail: boberg@lysator.liu.se, lha@augs.se       FidoNet: 2:204/404

PS: Are you planning of going to the K|ln fair (9-11 Oct)? We (Toolbox) might be
able to arrange transport.
-- 
     __________________________________________________________________________
     Michael Jansson	  mij@IDA.LIU.SE, uunet!liuida!mij, mij@SELIUI51.BITNET