Live data from Hacker News

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

morganwilde.svbtle.com

51–60 of 90 posts

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

#51
post #29

Install Valgrind. It makes error messages a lot less cryptic (my #1 problem with C... not that's it's limited to C). If you don't get proper feedback, it's not learning, just banging your head against the wall.

In a similar vain, learn how to use a debugger, such as GDB or DDD. Even the bare minimum (getting a stack trace from a crashing/segfaulting program) is incredibly helpful.

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

#52
In order to for people to really understand C and be proficient in it very clearly, I always recommend that they learn the basics of programming (memory, basic types, looping structures and array manipulation) in a simple assembly language such as 6502. This helps immensely with understanding pointers and deciphering the many cryptic C compiler messages.

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

#53
post #38

Earlier quoted context omitted.

Nice suggestion. Although I can't seem where one would have to look for those "pretty colours" you mentioned, I certainly can't see any of them on my Mac terminal...

Can't help you there -- but I don't think I've set any exotic terminal variables or anything like that, and I get this: http://i.imgur.com/BjWj7h6.png FWIW, I have: COLORTERM=gnome-terminal TERM=screen and Debian takes care of my termcap etc, afaik.

Think its his TERM env most likely being straight xterm (no color ansi escapes in the termcap iirc).

http://i.imgur.com/0Hzze9G.png

Thats me on osx running tmux with TERM=xterm-256color.

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

#55
post #42

By the way, I would love any feedback on this approach and where I should take this further.

As for going further staying with the bare-bones approach, I suppose you'd have to start looking at assembly output and how that fits with what the c-code does. I don't know anything about OSX x86_64 calling conventions etc -- but at least under Linux (and afaik windows) 64bits is a lot more friendly and fun than the mess that was 32bit (and 16bit) x86. There are a couple of great (free) resources on 32bit x86 assemb…

e12e, this is something I didn't think about, but fits perfectly into me theme of "zooming out". Thanks!

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

#57
post #33

Earlier quoted context omitted.

People don't like K&R? I can understand it not being suitable for children and the very beginner, but it's one of a very few programming books that is useful, succinct, pragmatic, doesn't get bogged down in APIs, and is written clearly. (The companion book "Programming in the UNIX environment" is the get-you-started guide from the very beginning, although it assumes 1970s terminal defaults)

K&R is the best second C programming book.

What's the first?

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

#58
post #29

Install Valgrind. It makes error messages a lot less cryptic (my #1 problem with C... not that's it's limited to C). If you don't get proper feedback, it's not learning, just banging your head against the wall.

I've had a heck of a time getting Valgrind working on a mac (especially since Mavericks), hardly finding any resources about it. Is there an alternative, or do you have any advice on getting it to work?

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

#59
post #22

Earlier quoted context omitted.

I once had a particularly slow week at work, and decided to write an article about how "Hello World" works in C. How it really works -- including compiling, linking, system calls, operating system involvement, hardware I/O, communication between ICs, etc. The path from the block of text to photons emitting from the screen, with fairly detailed explanations at every level. I ended up with a 50 page LaTeX document that…

I have been looking for a guide like that. I would also appreciate a release of the unfinished version.

Some resources on making tiny Hello World programs down to the kernel level that may be useful:

https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_fre...

http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...

http://timelessname.com/elfbin/

A wee bit heavy, but it's comprehensive. It deals with what happens when you run code, how the architecture of the computer works (by and large) including at the logic level:

http://www.amazon.co.uk/Computer-Systems-Programmers-Randal-...

If you want to go lower (and higher).. look at Understanding the Linux kernel for a good understanding of how an OS is put together, with specific examples i.e. Linux.

Code, by Petzold, deals with logic and computers from the ground up. It starts with relays and builds them up into gates and usable arithmetic blocks.

http://www.amazon.co.uk/Code-Language-Computer-Hardware-Soft...

http://www.amazon.co.uk/Understanding-Linux-Kernel-Daniel-Bo...

The physics is fairly simple, at least from a CRT or LED display perspective. Gets more tricky dealing with interconnecting microprocessors because a good chunk is vendor specific.

I think this kind of project is well suited to a guide on how to build a computer from the ground up, starting with logic gates, writing a real time OS and developing a scripting language that will run and compile on it. Then you can skip a lot of largely extraneous stuff and have a solid understanding of how the hardware works.

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

#60
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.

A more conservative rule would be not to use C where security is a concern, unless you know what you're doing.

When you're writing the kind of software that's an invitation to hackers, like a web application, you should favor a language like PHP or Ruby, which takes things like buffer overflows out of the equation, and even then, you should know what you're doing.

Post reply on HN