tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: once again, some discussion about <ctype.h> interfaces....



    Date:        Tue, 29 Jan 2013 05:32:11 -0500 (EST)
    From:        Mouse <mouse%Rodents-Montreal.ORG@localhost>
    Message-ID:  <201301291032.FAA10126%Sparkle.Rodents-Montreal.ORG@localhost>

  | > Also, is sizeof() defined when handed an expression,
  | Yes.  It returns the size of the expression's type.

Ah, OK, learn something new every day...

  | Yes...but the restriction of the domain to "unsigned char plus EOF"
  | came in at the same time, so either it's traditional code (which tests
  | the argument first) or now-standard code (which mustn't pass plain
  | char); there is no need to support the hybrid style which doesn't test
  | but passes plain char.  Such code is broken under either paradigm.

Not necessarily.   Consider

        char myname[] = "mouse";
        char MYNAME[sizeof(myname)];

        uppername()
        {
                char c, *p, *q;

                for (p = myname, q = MYNAME; c = *p++; *q++ = c)
                        if (islower(c))
                                c = toupper(c);
        }

There's no need for an isascii() as that is already known true.

But, and why I think people keep complaining, as even if the test is
there, and that function was written

                        if (isascii(c) && islower(c))  ...

gcc still issues a warning abut using a char as an array index.
That is, it doesn't do any flow analysis and detect that the code
has already guaranteed that c is not negative, it just complains.

However, having said that ...

  | I see no need to change anything here.

We agree on that (except possibly making gcc smarter, or less obnoxious).

kre

ps: I know my function doesn't copy the terminating \0 -- it doesn't need to.



Home | Main Index | Thread Index | Old Index