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

Re: adding all users to group



On Tue, Jan 22, 2002 at 05:11:20PM +0100, martin f krafft wrote:
| also sprach dman <dsh8290@rit.edu> [2002.01.22.1646 +0100]:
| > | > All of the users on a Debian system have UID >= 1000. For some unknown
| > | > (to me) reason, the user `nobody' has a UID of 65534 (or -1)
| > | 
| > | that's -2 btw ;)
| > 
| > Not if you use unsigned integers :-).
| 
| pfffffff.
| 
| cat << EOF > short_test.c
| #include <stdio.h>
| 
| int main(void)
| {
|   unsigned short s = -2;
|   printf("%d\n", s);
|   return 0;
| }
| EOF
| gcc -o short_test short_test.c
| ./short_test
| 65534

Well, sure, the C compiler isn't going to verify that you're putting
valid bits into memory.  Technically that assignment is illegal since
-2 is not an unsigned int.  (java barfs at stuff like this, though it
doesn't comprehend unsigned data; odd that at runtime it still wraps
around)

Just as an example, still using C :

#include <stdio.h>

int main()
{
    unsigned short s = -2 ;
    signed short t = -2 ;

    if ( t < s )
    {
        printf( "t, %d, is less than s, %d" , t , s ) ;
    }
    else
    {
        printf( "t, %d, is not less than s, %d" , t , s ) ;
    }
    return 0 ;
}


$ ./a.out 
t, -2, is less than s, 65534


I was surprised to not see any warnings about comparing signed and
unsigned data even though I used "-Wall -Werror".  The compiler
actually did the comparison correctly (I wasn't even sure on that
point; given the strength/weakness of C's type system).  Even though I
gave them the same value, they aren't "equal" :-).



(BTW, for those who haven't dealt with two's complement binary
arithmetic before, we all agree that 65534 and -2 have the same bit
pattern in memory)

-D

-- 

All a man's ways seem innocent to him,
but motives are weighed by the Lord.
        Proverbs 16:2



Reply to: