Live data from Hacker News

Where to begin when learning C? Start by making lots of errors

morganwilde.svbtle.com

1–10 of 90 posts

Re: Where to begin when learning C? Start by making lots of errors

#4
post #3

By making sure to enable all warnings , enable warnings as errors and use a compiler that integrates static analysis like clang.

I am using the default `cc` compiler on Mac OS X for this without any flags, are you saying I should something non-stock in this case?

Re: Where to begin when learning C? Start by making lots of errors

#5
post #3

By making sure to enable all warnings , enable warnings as errors and use a compiler that integrates static analysis like clang.

It's essential to follow pjmlp's advice, since C does otherwise not give a lot of feedback about one's mistakes: learning from one's mistakes might take a long time since a quite broken program (think overwriting past memory strictly allocated for one entity) might still lead to a working program.

Use your compiler, use it well with all its warnings. Run your programs under valgrind or some such.

Re: Where to begin when learning C? Start by making lots of errors

#6
post #3

By making sure to enable all warnings , enable warnings as errors and use a compiler that integrates static analysis like clang.

I am using the default `cc` compiler on Mac OS X for this without any flags, are you saying I should something non-stock in this case?

Try passing at least the -Wall and -Wextra flags.

For learning, you could also add -ansi, as it will make your compiler be stricter about standards.

Re: Where to begin when learning C? Start by making lots of errors

#7
I learned C by reading K and R and doing the book's exercises . . . on paper. At the time I didn't have access to a C compiler, so I wrote them all out in a notebook. A month later I got a job at a shop that was running Unix, and got the chance to type my programs in and try them.

I had a lot of things wrong. It took me a while to understand the difference between control-D and EOF, for instance (how embarrassing). But the 30 days I spent without a compiler made me think about program behavior.

I'm not saying this is a great way to learn a language, but it can be done.

I keep hearing people complain about K and R being "a terrible book." For me it was perfect: pragmatic, succinct, with great examples and good exercises.

Re: Where to begin when learning C? Start by making lots of errors

#8
post #3

By making sure to enable all warnings , enable warnings as errors and use a compiler that integrates static analysis like clang.

I am using the default `cc` compiler on Mac OS X for this without any flags, are you saying I should something non-stock in this case?

The Mac OS X C compiler is clang, no need to install anything extra.

C is insecure by design and IT is still paying for its widespread, when used by developers that don't use the best practices for secure C coding.

So when learning how to use it, the best way is to learn those best practices from day one.

Re: Where to begin when learning C? Start by making lots of errors

#9
post #7

I learned C by reading K and R and doing the book's exercises . . . on paper. At the time I didn't have access to a C compiler, so I wrote them all out in a notebook. A month later I got a job at a shop that was running Unix, and got the chance to type my programs in and try them. I had a lot of things wrong. It took me a while to understand the difference between control-D and EOF, for instance (how embarrassing). B…

I guess this is sort of I'm thinking about this, that is forcing people first to think how something should work, rather then just duplicating some code and seeing that it works. Thanks for sharing!

Re: Where to begin when learning C? Start by making lots of errors

#10
post #8

Earlier quoted context omitted.

I am using the default `cc` compiler on Mac OS X for this without any flags, are you saying I should something non-stock in this case?

The Mac OS X C compiler is clang, no need to install anything extra. C is insecure by design and IT is still paying for its widespread, when used by developers that don't use the best practices for secure C coding. So when learning how to use it, the best way is to learn those best practices from day one.

Absolutely, but my way of going about this would be to first show _why_ something is a best practice, rather than forcing people to take it at face value.
Post reply on HN