[lkml]   [2007]   [Feb]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: somebody dropped a (warning) bomb

On Thu, 8 Feb 2007, J.A. Magallón wrote:
> Perhaps the problem is that gcc warns you something like 'if you care
> anything about the sign behaviour of what you send to strlen() you're doomed'.

But you *cannot* care. That's the point. The warning is insane. For any
function that takes "char *", you very fundamentally *cannot* care about
the signedness of the argument, because doing so would be wrong. If you
do care, you're already buggy.

> Ie, you declared the var unsigned, so you care about it. But I can do
> anything without any regard to the sign.

That makes no sense.

First off, "strlen()" doesn't care about the sign of the buffer, so it's a
bad example anyway. But take something that *can* care, namely "strcmp()",
which can return different things depending on whether "char" is signed or
not (is 0xff larger than 0x00? Depends on whether char is signed or

But THE CALLER CANNOT AND MUST NOT CARE! Because the sign of "char" is
implementation-defined, so if you call "strcmp()", you are already
basically saying: I don't care (and I _cannot_ care) what sign you are

So having the compiler warn about it is insane. It's like warnign about
the fact that it's Thursday today. It's not something the programmer cares

 \ /
  Last update: 2007-02-08 22:45    [W:0.148 / U:2.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site