c programming style
Scott Pace
scott at othervax.UUCP
Thu Jul 18 01:37:07 AEST 1985
In article <935 at teddy.UUCP> rdp at teddy.UUCP (Richard D. Pierce) writes:
>
>One of the points with the C i++ versus i = i = 1 issue is the one of
>pointers (although some alluded to it).
>
>Say we have some item like:
>
>
> main(argc, argv)
> int argc;
> char **argv;
>
>stepping through the array of pointers can be done by by incrementing
>a pointer:
>
> while (condition) /* or some other loop construct */
> . . .
>
> argv++;
>
>This will get us to the next pointer, whereas,
>
> argv = argv + 1;
>
>will NOT (unless by the happy happinstance that a pointer is exactly
>the same size as a character!)
>
>The only equivalent "clear" statement would be:
>
> argv = argv + sizeof(char *); !
>
BULLSHIT!!!
Turn to page 96 of K&R.
Quoted without permission:
"5.4 Address Arithmetic
If p is a pointer, then p++ increments p to point to the next
element of WHATEVER kind of object p points to, AND p+=i increments p
to point i elements beyond where it currently does."
So if we say i has the value 1;
p++
++p
p+=i
and since p+=i is equivalent to p = p + i
all four forms have EXACLTY the same effect on p.
And in our case:
++argv
argv++
argv+=1
argv=argv+1
are ALL EQUIVALENT!!!
Read the book next time.
Scott Pace, Philips Info. Sys. Ltd., Montreal, Canada
philabs!micomvax!othervax!scott
More information about the Comp.lang.c
mailing list