c programming style

John P. Nelson john at genrad.UUCP
Tue Jul 16 07:05:17 AEST 1985


In article <935 at teddy.UUCP> rdp at teddy.UUCP (Richard D. Pierce) writes:
>	char **argv;
>
>	  . . . 
>
>	  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!)

Well, I personally like ++argv best, but the argument above is just NOT TRUE!
Referring to K&R page 94:

    int *pa

    . . .

    The definition of "adding 1 to a pointer", and by extension, all pointer
    arithmetic, is that the increment is scaled by the size in storage of the
    object that is pointed to.  Thus in pa+i, i is multiplied by the size of
    the objects that pa points to before being added to pa.



More information about the Comp.lang.c mailing list