Wednesday, September 19, 2007

Hello World!

First post, Here goes!
Please comment :)


// This is a comment, everything in comments are ignored
// in C. More specifically the C preprocessor removes
// them before the compiler has a chance to ignore it.

#include <stdio.h>
#include <stdlib.h>

// stdio declares various standard input/output functions
// we need to include it for the prototype of printf
// #include is like a textual substitution of the files
// content with that line.

// stdlib defines EXIT_SUCCESS which any working program
// should return when it halts execution, unless of course
// somthing miserable happened.

int main(void) {
// main is the function which every standalone C program
// defines, The OS will load up the program and call main
// then the ball starts rolling and, then..!

printf("Hello world!\n");

// Well there many subtle dangers to be aware of with here..
// Why on *earth* are you printf?
// Lets see what printf actually does:
//
//>> `man printf`
//>>
//>> int
//>> printf(const char * restrict format, ...);
//
// First of all printf takes a 'format' *that* doesn't sound
// like what *we* give it.. What format is the format!
//
// Well there are several pages of very scrutinous detail about
// about this apparently simple function infact there's even
// 8 lines talking about its "BUGS"!!
// If you put down printf("%s") no-one knows what will happen
// You and I certainly don't (and can't), This is Unspecified
// Behavior (Dangerous, A major cause of BUGS!).
//
// All we wanted was a bit of text output, and
// there's a function that does just that:
//
//>> int
//>> puts(const char *str);
//
// This would suit our task, and print a newline to boot!
// (the reason for doing that is most terminals are
// line buffered so you wont see anything until you
// hit the next line, or flush stdout.)
//
// So one should have wrote puts("Hello world!") instead.
// Let's see how we can avoid using Dangrous and
// Unnecessary tools for simple tasks in future.

return EXIT_SUCCESS;

// 'return' is like jumping out of the function with,
// in this case the value of EXIT_SUCCESS. That means that
// nothing down here can ever be reached, we're in
// No-Mans-Land.
}

No comments: