break, continue, return, goto (net.religion.c)
Isaac Dimitrovsky
dimitrov at csd2.UUCP
Fri Nov 15 08:10:00 AEST 1985
[]
> Can anyone suggest a recoding of the following example without using
> multiple returns? Of course it can be done, but in a clearer, simpler
> way? Remember, this is exactly the same as using loops with continue.
>
> core(file)
> char *file;
> {
> if ((fd = open(file, O_RDONLY)) < 0) {
> perror(file);
> return;
> }
> if ((n = read(fd, &u, sizeof u)) == 0) {
> puts("zero length");
> return;
> }
> if (n < sizeof u) {
> puts("too small");
> return;
> }
> if (BADMAG(u.u_exdata.ux_magic)) {
> puts("not a core dump");
> return;
> }
>
> /* process core dump */
> printf("%d/%d %s", u.u_uid, u.u_gid, ctime(&u.u_start));
> printf("$ %s\n", u.u_comm);
> /* ... etcetera */
> }
core(file)
char *file;
{
if ((fd = open(file, O_RDONLY)) < 0)
perror(file);
else if ((n = read(fd, &u, sizeof u)) == 0)
puts("zero length");
else if (n < sizeof u)
puts("too small");
else if (BADMAG(u.u_exdata.ux_magic))
puts("not a core dump");
else {
/* process core dump */
printf("%d/%d %s", u.u_uid, u.u_gid, ctime(&u.u_start));
printf("$ %s\n", u.u_comm);
/* ... etcetera */
}
}
Oh no!!!
Not the straightjacket again!!!
Gaaahhhhhrrgh....
Isaac Dimitrovsky
allegra!cmcl2!csd2!dimitrov (l in cmcl2 is letter l not number 1)
251 Mercer Street, New York NY 10012 (212) 674-8652
... Hernandez steps in to face ... Orl ... HERchiiiser ... and it's a liiine
driive, deeeeep to the gap in left center ... - Bob Murphy, Voice of the Mets
More information about the Comp.lang.c
mailing list