Messages in this thread | | | From | Timothy Covell <> | Subject | Re: RFC: booleans and the kernel | Date | Sat, 26 Jan 2002 01:22:02 -0600 |
| |
On Friday 25 January 2002 00:13, Alexander Viro wrote: > On 25 Jan 2002, Xavier Bestel wrote: > > le sam 26-01-2002 Ю 00:09, Timothy Covell a Иcrit : > > > #include <stdio.h> > > > > > > int main() > > > { > > > char x; > > > > > > if ( x ) > > > { > > > printf ("\n We got here\n"); > > > } > > > else > > > { > > > // We never get here > > > printf ("\n We never got here\n"); > > > } > > > exit (0); > > > } > > > covell@xxxxxx ~>gcc -Wall foo.c > > > foo.c: In function `main': > > > foo.c:17: warning: implicit declaration of function `exit' > > > > I'm lost. What do you want to prove ? (Al Viro would say you just want > > to show you don't know C ;) > > And why do you think you never get there ? > > I suspect that our, ah, Java-loving friend doesn't realize that '\0' is > a legitimate value of type char... > > BTW, he's got a funny compiler - I would expect at least a warning about > use of uninitialized variable.
Java lover's computer gcc -v says:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)
I realize that '\0' is a legit character. And before you start, I also realize that a string is a null terminated list of characters (yuck). My point is to be clean about one's code. For example, Mark Hahn sent me a bit of C based strlen code, but I prefer the Linux kernel implementation which is more explicit and doesn't make funky implicit nor explicit casts. Kernel code: (And, of course, glibc uses Assembly for strlen).
#ifndef __HAVE_ARCH_STRLEN /** * strlen - Find the length of a string * @s: The string to be sized */ size_t strlen(const char * s) { const char *sc;
for (sc = s; *sc != '\0'; ++sc) /* nothing */; return sc - s; } #endif
-- timothy.covell@ashavan.org. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |