Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site eagle.UUCP Path: utzoo!watmath!clyde!burl!ulysses!eagle!mjs From: mjs@eagle.UUCP (M.J.Shannon) Newsgroups: net.lang.c Subject: Re: c programming style Message-ID: <1289@eagle.UUCP> Date: Sat, 20-Jul-85 08:59:04 EDT Article-I.D.: eagle.1289 Posted: Sat Jul 20 08:59:04 1985 Date-Received: Mon, 22-Jul-85 05:45:02 EDT References: <13@brl-tgr.ARPA> <1303@uwmacc.UUCP> Organization: AT&T Bell Laboratories, Summit, NJ Lines: 42 > To my trained and experienced mind, incrementing > and adding a constant are very different things (and C programmers and > language developers are not gods :-). > -- > - joel "vo" plutchak The theory is this: if you declare a variable to point to a particular type of object, you *should* be manipulating objects. The compiler (or, more precisely, the language specification) states that arithmetic on the pointer is done in multiples of the object's size. Since the expression *(E1+E2) is semantically equivalent to E1[E2], it is very reasonable that the value of either expression is the object E2 ahead of E1, no matter how big the object is. Even fortran and pascal define the semantics of indexing the same way. Language consistency demands that pointer arithmetic be defined as it is. Yes, you can bitch & moan to your heart's content, but I (for one) will refuse to (linearly) step through a symbol table like this: struct symtab { char * name; long value; int flags; }; struct symtab symtab[1024]; ... for (sp = &symtab[0]; sp->name != NULL; sp += sizeof (struct symtab)) ... when I should be able to say: ... for (sp = &symtab[0]; sp->name != NULL; ++sp) ... (For nit-pickers, yes, there should be tests for reaching the end of the symbol table, but the point here is to illustrate pointer manipulation.) -- Marty Shannon UUCP: ihnp4!eagle!mjs Phone: +1 201 522 6063