Pointer incrementation and assignment

Jeff Boeing abcscagz at csuna.csun.edu
Fri May 26 07:58:21 AEST 1989


This has bugged me for quite some time....

     int *a;

Say you implement this on a machine that uses byte addressing (memory location
4000 contains 1 byte, memory location 4001 contains 1 byte, and so on), and
this particular C compiler, quite justifyably, interprets an "int" to be a
signed two-byte value.  Now, by definition, when you do this:

      a++;

You increment the actual address stored in a by TWO, not just by one.
Furthermore, if the compiler allows it, this is also perfectly legal:

      a = 4000;

This sets a to point to memory location 4000.  A subsequent a++ would increase
a to 4002.  But would doing this:

      a += 1;

increase a by 1 or by 2?  Or how about

      a = a + 1;

??  Inquiring minds want to know!

-- 
Jeff Boeing:  ...!csun.edu!csuna!abcscagz    (formerly tracer at stb.UUCP)
----------------------------------------------------------------------------
"Let's split up -- we can do more damage that way."
                       -- Gh0stbusters



More information about the Comp.lang.c mailing list