Dave Hall Consulting logo


$ cat hello_world.c #include <stdio.h> main() { printf ("Hello World!\n"); }
$ gcc hello_world.c -o hello_world
$ chmod +x hello_world
$ ./ hello_world
Hello World!

I have started playing with C recently. I am still finding it annoying, yet enjoyable at the same time. The PHP developers have spoilt me (and other PHP coders). PHP gives you most of the power of C, without having to deal with annoying string handling, easy arrays, memory management and having to build to test. I am sure there is more.

Unlike OS X, I think I will persist with C.

Other than reminding myself of how to do hello world in C, why did I post this? I thought you would never ask, it is because my blog is now syndicated on Planet Linux Australia. I am pretty honoured by being added. Hopefully there are others who appreciate my rants :)

GCC tips

Anonymous wrote:


The exmaple you gave was not really a good one. First of all, the main function must (according to the C standard) return int and secondly you should actually return a value. Ie:

int main () { printf ("Hello world.\n") ; return 0 ; }

One thing that would help with this is turning on warning flags when compiling. I suggest something like:

gcc -W -Wall -Werror hello.c -o hello

Finally when you use #include statements in a blog post, you need to make sure that <stdio.h> doesn't get mistaken for a HTML tag.


Added Tue, 2007-05-29 08:09

Re: GCC tips

Dave wrote:

Thanks for the tips.

I fixed the #include, but left the rest so people can see how bad my C coding skills really are :)

Added Tue, 2007-05-29 09:32

PG Tips

Chris Samuel wrote:

I've always thought the idea was for cases where you weren't going to deal with arguments (what, you don't want ./hello_world --version ?) you should do this:

int main(void)

Make sense ?

cheers! Chris

Added Thu, 2007-05-31 22:30