Which compiler to use with K&R book?

Sep 6, 2011 at 8:11am
I just started reading the C programming K&R book, it's an old book from 1988. So how am I gonna write programs with this book? Is there any software out there that I can use with this book?
Last edited on Sep 6, 2011 at 2:54pm
Sep 6, 2011 at 8:21am
Do you mean compilers?
http://www.cplusplus.com/forum/articles/7263/

Or something else?
Sep 6, 2011 at 8:22am
closed account (1vRz3TCk)
Any compliant C compiler will do the job.

What OS are you using?

Edit:
A few additional books that you may find useful for you studies (check your library).
Practical C Programming by Steve Oualline
Mastering Algorithms with C by Kyle Loudon

and finally a good pocket reference (worth buying as it is cheap):
C Pocket Reference by Peter Prinz and Ulla Kirch-Prinz
Last edited on Sep 6, 2011 at 8:42am
Sep 6, 2011 at 11:26am
I'm using W7 64-bit. Are there any compatible C compilers for W7?
Sep 6, 2011 at 11:37am
closed account (1vRz3TCk)
Code::Blocks with MinGW ( http://www.codeblocks.org/ )
Sep 6, 2011 at 11:39am
I have codeblocks
Last edited on Sep 6, 2011 at 2:53pm
Sep 6, 2011 at 11:52am
closed account (1vRz3TCk)
The last time I looked at it, it gave you the option of language on the console project, try reading the help files (I don't use Code::Blocks other than for small test files). Code::Blocks is an IDE, you can get it to use the C compiler from the MinGW tool chain it just needs configuring.

Sep 6, 2011 at 11:54am
I tried using the code in the K&R book, but CB gave me 1 error, it seems I can't use the code from the book to write.
Last edited on Sep 6, 2011 at 12:10pm
Sep 6, 2011 at 12:15pm
The book is old, I recommen getting a new one, otherwise you might be learning stuff that will have to unlearn.

Post the code you were trying to compile, it could be one of those cases.
Sep 6, 2011 at 12:20pm
i guess the compiler you needed just an up-to-date C compilers. the book's age doesn't matter (i guess, except there's a new syntax beyond it). or probably you can just download the tutorial from this site and just find yourself a VS 2008 express edition
Sep 6, 2011 at 1:19pm
#include <stdio.h>
main()
{
printf("hello, world\n");
}

This is the book's code. But the main.c in codeblocks which is also hello world is different.
Last edited on Sep 6, 2011 at 1:19pm
Sep 6, 2011 at 1:49pm
closed account (1vRz3TCk)
Just tried that code in Code::Blocks and it worked fine.

File->new->project...
Selected Console application and clicked go
clicked next on the next page
Selected C and clicked next
gave it a Title and clicked next
left it on GNU GCC and clicked Finish

Opened main.c and replaced it with the code above and compiled and ran
Sep 6, 2011 at 2:35pm
btw it should be:
 
int main() //main() should return an int value 
Sep 6, 2011 at 2:45pm
it worked but i had 1 warning. So do I need to heed the warnings? Is it important for a program to have 0 warnings?
Last edited on Sep 6, 2011 at 2:52pm
Sep 6, 2011 at 2:47pm
int main() is required in C++, but not in straight C.
Sep 6, 2011 at 3:10pm
closed account (1vRz3TCk)
it worked but i had 1 warning. So do I need to heed the warnings? Is it important for a program to have 0 warnings?
It depends on what the warning was. I would asume that it was to do with 'int implicate type specifier no longer assumed'.

In C, if you omit the type specifier, e.g. the int in int main(), the compiler will assume that it is an int. In C99 this assumption is no longer valid and will result in either a warning or an error depending on the compiler (a warning is more usual due to backward compatibility).

Generally having zero warnings is preferable but understanding warnings and deciding if they are a problem or not can be acceptable.
Sep 6, 2011 at 3:50pm
ok thx guys, I got what I need now.
Sep 6, 2011 at 9:40pm
Er, no one has yet said that K&R is not standard C. You need a compiler that can compile pre-ISO Standard C89.

The GCC is pretty good at handling K&R C, but there are some Incompatibilities:
http://gcc.gnu.org/onlinedocs/gcc/Incompatibilities.html

What exactly is giving you grief?

[edit] I came back and read this again and realized that I must have mixed thoughts on my first sentence, leaving it to say something I did not mean... I fixed it. ;-)
Last edited on Sep 7, 2011 at 2:32am
Sep 6, 2011 at 9:57pm
closed account (1vRz3TCk)
The 1988 second edition is standard, well the first printing is 'based on' but the second printing was updated to the published standard.
Topic archived. No new replies allowed.