[PLUG] C programming

Stuart Jansen sjansen at buscaluz.org
Thu Aug 28 10:55:57 UTC 2008


On Wed, 2008-08-27 at 16:59 -0700, rich wrote:
> main(){
>     printf("hello, world.\n");
> }

Several people have already explained that you need
#include <stdio.h>

It might be good at this point to explain why the book your reading may
not have mentioned that. In the past, GCC was less picky than it is now.
Once upon a time, the above code would have compiled. As GCC has
improved, its ability to recognize errors and provide warning has
improved. While this results in higher quality code in the long term, in
the short term it makes GCC more annoying. If you find your book
repeatedly omits information necessary to compile with a modern GCC,
perhaps you will need to find a more correct book.

May I also suggest some flags to make GCC even pickier? This will help
you to learn good habits from the beginning.

gcc -pedantic -Werror -Wall -Wextra -Wfloat-equal -Wformat=2
-Wno-unused-parameter

This is only a taste of what GCC can do. Once you're more comfortable
with C, you may want to add extra checks like:
-Wtraditional -Wwrite-strings

I don't know how much you care about backwards compatibility. I don't
care much so I prefer coding against C99 instead of GNU C90, even though
GCC doesn't fully implement C99 yet.
-std=c99

You'll find that C is a grotty language with a complex history, but it's
also beautiful in its own way. Have a lot of fun!




More information about the PLUG mailing list