no need to. size_t is unsigned (according to c99). ssize_t is signed. (BTW, if it weren't this way, a malloc of < 0 would be crazy!)
But if you'd like to verify both:
first, confirmation that size_t is unsigned (without grep'ing the standard):
Code:
root@bt:~# cat sizet.c
#include <stdio.h>
#include <string.h>
int main()
{
size_t usize;
signed int ssize;
memset(&usize, 0xff, sizeof(usize));
memset(&ssize, 0xff, sizeof(ssize));
if(usize < 0)
printf ("size_t < 0\n");
if(ssize < 0)
printf ("int < 0\n");
return 0;
}
root@bt:~# gcc -o sizet sizet.c
root@bt:~# ./sizet
int < 0
root@bt:~#
Second, the re-run:
Code:
$ gcc -o test-long test-long.c -m64 -ansi
test-long.c: In function âmainâ:
test-long.c:5: warning: format â%dâ expects type âintâ, but argument 2 has type âlong unsigned intâ
$ ./test-long
sizeof(long) == 8
If you'll notice, the warning message has changed slightly. I expect that the first example on my Ubuntu x64 machine would produce errors regarding comparisons between unsigned and < 0 (always being false). No matter, the real issue that the warning reveals is that we should use %u for 32-bit machine, and %lu for 64 bit machine. (the return width of sizeof varies on architecture type)
EDIT: we're veering way off-topic, here. We should probably take the rest of this to PM (or, mods willing, start a different thread).