Sujet : Re: The joy of FORTRAN
De : bowman (at) *nospam* montana.com (rbowman)
Groupes : comp.os.linux.miscDate : 03. Mar 2025, 06:28:50
Autres entêtes
Message-ID : <m2kt0iFsoc0U2@mid.individual.net>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Pan/0.160 (Toresk; )
On Sun, 02 Mar 2025 23:12:28 GMT, Charlie Gibbs wrote:
Another thing I do to make code compact is to omit the braces if the
body of the if or for is a single line. However, I won't do this if the
next line is up two or more levels, since I want everything to be
accounted for with braces. For instance:
for(i = 0; i < 10; i++) {
printf("%d\n", i);
if((i % 2) == 0) /* Omitted braces */
printf("The preceding number is even.\n");
if((i % 3) == 0) {
printf("The preceding number is a multiple of 3.\n");
} /* Don't go up two levels without braces! */
}
>
I tend to use the braces for ifs out of self defense. I've been burned a
couple of times with stuff like
if (foo == bar)
exit(-1);
and at some later time deciding some logging would be nice.
if (foo == bar)
log("something went off the rails!):
exit(-1);
I also do things like test the return of malloc(). I know if malloc()
returns NULL I probably have a snowball's chance of logging or doing
anything graceful but it's worth a try.