Re: Shut Up With The Open Source Politics, OK?
Adam Ophir Shapira <[email protected]>
| Newsgroups | gmane.linux.usability.annoyances |
|---|---|
| Message-ID | <[email protected]> |
Actually, there *is* a potential bug here, but that
bug is *not* the failure to check the return value
of the function.
The potential bug is the failure to flush the
output. I have been taught that you can't take
it for granted that it will be done for you
in <stdio>.
Also, one thing that's annoyed me with many
a Hello program is the fact that the next prompt
*always* appears on the same line as the output.
When I write a Hello program, therefore, I always
take care of that.
Here's a bug-free version of the Hello program:
#include <stdio.h>
int main ( int argc, char **argv, char **environ )
/* Some compilers will complain without the full */
/* header for the main() function. */
{
printf("Hello, World!\n");
fflush(stdout);
return 0;
/* Some compilers will complain if main() */
/* lacks a return value. */
}
John wrote:
>On 11 Oct 2003 at 10:52, [email protected] wrote:
>
>>You mean:
>>
>>#include <stdio.h>
>>main()
>>{
>> printf( "Hello, world" );
>>}
>>
>>?
>>
>>There's a bug there, in that it doesn't check the return code from printf().
>>
>
>Not a bug. You are allowed to ignore the return code of a
>function if you don't intend to do anything with it. If you want
>to trap an error, and do something about it then it's another
>matter. Obviously here Brian & Dennis decided, wisely, that if
>it wrote to stdout all was fine, and if it didn't you'd find out
>soon enough without extra complications in the code. Checking
>the return value is not mandatory, and sometimes completely
>useless.
>
>However it might be wise to declare the type of main() (my compiler
>grumbles if you don't), and if "int", then have "exit 0" as the last
>statement :^)
>_______________________________________________
>annoyances mailing list
>[email protected]
>http://michelangelo.renaissoft.com/mailman/listinfo/annoyances
>
>