Path: utzoo!attcan!uunet!husc6!rutgers!gatech!mandrill!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon S. Allbery) Newsgroups: comp.sources.d Subject: Re: Something's Broken: was ... Re: tgetent Message-ID: <11936@ncoast.UUCP> Date: 23 Jul 88 01:18:24 GMT References: <54@libove.UUCP> <701@nod2sco> <3222@bigtex.uucp> <1033@ficc.UUCP> <19789@watmath.waterloo.edu> <1305@ucsfcca.ucsf.edu> <19829@watmath.waterloo.edu> Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Followup-To: comp.sources.d Distribution: comp Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 41 As quoted from <19829@watmath.waterloo.edu> by rwwetmore@grand.waterloo.edu (Ross Wetmore): +--------------- | In article <1305@ucsfcca.ucsf.edu> root@cca.ucsf.edu (Computer Center) writes: | >In article <19789@watmath.waterloo.edu>, rwwetmore@grand.waterloo.edu (Ross Wetmore) writes: | >> The assumption that pointers and ints are of equal length is the | >> problem, no? This is a fundamental assumption of the 'C' language, | >> if not an explicit requirement. | >Please learn what you are talking about before posting. See K&R p. 210 | > A pointer may be converted to any of the integral types large | > enough to hold it. Whether an int or long is required is machine | > dependent. | | (int)n = (char *)p - (char *)q; | | This is perfectly valid 'C' and will never to my knowledge be picked | up by any lint program. While 'C' goes to great lengths to tell you all | about the non-portability of many of its features (I have read the | Bible above from cover to cover), the above statement has a fundamental | assumption that the separation of two addresses is representable by an | integer value, or if you regress one step taking into account the +--------------- Not only have I used a lint (System V? Can't check, I'm on ncoast, whose lint and cc are braindamaged anyway) which complains about "illegal pointer subtraction" when handed this, but Microsoft's cc for Xenix and 386 Unix flatly refuses to compile a program which does this with basically the same message. (You can defeat it with a cast to (int) or (long), of course.) I think ANSI defines pointer subtraction only when the pointers are known to point to the same contiguous block of memory (i.e. within a single array). Otherwise, pointer subtraction may not even be meaningful. (It could cause a SIGBUS on an architecture which stores teo arrays in totally different memories -- not two parts of the same memory but a "nonscalar" memory.) C itself lets you do this -- that is why "lint" exists; C gives you enough rope to hang yourself (but usually it's us non-Vax types who get hanged by Vaxoid programs). ++Brandon -- Brandon S. Allbery, uunet!marque!ncoast!allbery DELPHI: ALLBERY For comp.sources.misc send mail to ncoast!sources-misc