[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: using the interfaces in ctype.h
> Ah, right, OK, sorry, my mistake. However that's really just a
> pedantic point irrelevant to my main argument. So, -1, which in our
> case happens to be EOF, is OK.
Well, more to the point, we arranged that EOF was OK, because that's
the way the interface is defined. That we did so by making EOF -1 and
providing an offset of 1 is an implementation detail.
> However that does nothing to help for any other negative values.
> Assuming that the caller will only use -1 or a value between 0 and
> _CTYPE_NUM_CHARS is not safe when the implementation is accessing an
> array of only _CTYPE_NUM_CHARS+1 and the prototype for the API
> specifies a parameter of type "int".
That makes about as much sense as saying that getc assuming its FILE *
parameter is non-nil is not safe, or that mktemp is not safe when
passed (void *)&main. Large swaths of libc will do odd things when
passed arguments beyond their interface specifications; it is no part
of libc's mandate to detect such calls. I'm not convinced "not safe"
is really a fair term to apply to such behaviour. I certainly don't
see it as worth significant effort to do anything in particular in such
>> For example (assuming 8-bit chars), if the implementation did the
>> equivalent of
>> c = c & 0xff;
> Furthermore how's that any different than suggesting that the caller
> cast the parameter with "(unsigned char)" or "(int)(unsigned char)"?
The difference is the difference between application code and the
implementation of the interface: the application code can tell whether
it's passing something extracted from a char buffer (which cannot
conceptually be EOF) rather than something returned from getc (which
I don't think anyone has suggested application-level casting for cases
where the argument might be EOF; that would be severely broken - which
is why the implementation, which must be prepared to handle EOF
arguments, should not do it (nor anything equivalent).
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents.montreal.qc.ca@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Main Index |
Thread Index |