Handmade Hero»Forums»Code
117 posts
Code hacker/developer
C Programming Resources/Algorithms
So I'm having an interesting time finding specific C programming resources... I think it's because "C Programming" in general sort of includes C# and C++... So I end up finding C++, C#, and other resources rather than C-specific resources. I did find this post which is probably the most comprehensive that I've found thus far. Other than that, is there much differentiation between C/C++ these days or are you basically using C++ without the OOP parts? I'm a current C# programmer and I'm really trying to break into the C world because I find the low-levelness fascinating.

Second question is, how important is formal training in algorithms? I just started the MIT Open Courseware Algorithms course, complete with the 1300 page textbook. It's quite an undertaking since I haven't done any college-level math in about 6 years, however, it is doable... But will take considerable time. Is this time well spent for a software developer? Thanks.
Abner Coimbre
318 posts / 1 project
Founder
C Programming Resources/Algorithms
Edited by Abner Coimbre on Reason: Added concrete advice.
Todd
I'm a current C# programmer and I'm really trying to break into the C world because I find the low-levelness fascinating.

Hey Todd,

It's superb you find it fascinating. To test that interest, you could venture into programming in something with a strong correspondence between language and processor family machine instructions (i.e. asm). Pick a friendly chip like MIPS or 6502, perhaps Z80 and study just enough to get a solid feeling of the basics: stuff like machine cycles, knowing an instruction rate against clock speed, playing with register values, jumping to specific addresses, I/O controllers on the bus, why device drivers exist, etc. Anything that'll improve your fundamental knowledge of computers. To quote an ASM author:

it is necessary to actually learn the assembly language and details of a particular processor, and to write programs for it. This is somewhat like those experiments you did in high school chemistry. Their goal was to teach you the fundamentals of chemistry, not to teach you how to make test tubes full of colorful water. But without the colorful experiments your understanding of chemistry might remain abstract and vague, and would soon be forgotten.

Many of us have just a vague understanding of what's actually going on (some legitimately don't know at all!), which I suspect is why you find "low-levelness" intriguing? However, C is a high-level language, whose input is fed to a program for processing. When you know what it's processed into beforehand (by having written a reasonable number of small-to-mid-level assembly programs), you'll be at the optimal place to reap the benefits of learning C. New questions about which X thing to learn next are immediately answered after this essential phase. You might also find yourself taking a backseat to most modern wars on languages and software development practices (hint: they're surface-level concerns and not worth your time); it's liberating. This study route will take much longer, but you would find even more difficult advice from Knuth. For more concrete advice on C, go with the K&R book, and then about the first 40 episodes of Handmade Hero. I think you'll be where you want to after that.

Yes, take algorithm study very seriously, but take learning your assembly / C with equal if not more importance.
36 posts
C Programming Resources/Algorithms
Edited by graeme on
I think the quickest way to get up to speed with C is to write a simple allocator that allows freeing. It has all the things that you need to know with C that have been tucked away in higher level languages--pointers and pointer arithmetic, working with buffers of bytes, how structs relate to memory, etc, and very little else. And you'll also want to understand undefined behaviour, which might save you time debugging in the future

I think a good more recent overview of C (and not C++) is this book, Modern C. It's not perfect but importantly it covers newer features like static_assert (which is in c++ too)

But unlike other languages where learning them is learning their standard library, with C all thats left to learn is algorithms and data structures. I've found that you rarely see any college level math unless you're implementing algorithms to perform college level math

Incidentally with MIT OCW I've found the best way to learn from those is to read the book they are teaching from ahead of the lectures you are watching. You get the details from the books and the bigger picture + more practical side from the lectures. It's good!! Why did I do it the other way around at university!!!
117 posts
Code hacker/developer
C Programming Resources/Algorithms
Thanks so much for Modern C! What a fantastic resource! I love the personal touch the author adds as well, explaining some brief history and culture.

Also, it's liberating to hear someone finally differentiate C from C++... I'm so tired of hearing "C/C++!"

Anyways, thank you both for the solid advice and resources. Yes, I am indeed also interested in assembly language, and I'm starting to be able to wrap my head around and figure out the sort algorithms in the MIT book, which is also a lot of fun...

I have just one more question for you... Are there any C-oriented communities out there that you would recommend? Most forums I find are C#, JavaScript, Java, and C++, and once again, it can be tough to track down a C-specific community. But at least I know I have this one and StackOverflow! Thanks again!
John Burton
3 posts
C Programming Resources/Algorithms
I've been writing c++ professionally for quite a few years now and for work I'm expected to write 'modern' c++ but increasingly I've been dissatisfied with it.

When i first watched a few of these videos I was amazed. This style just seems so much more productive.

However I find it hard to write. I understand the language well. What I don't understand is how to structure good code in C or C-style C++

I tend to build structs that contain my data then pass them by pointer to functions. But is that the best way? It feels too much like c++ classes without the syntax. How do i allocate memory and safely ensure it is freed. There presumably are patterns and idioms in C to do this reliably. And how do I structure code? In c++ I'm pretty much expected to have one file per class and one for its header. But that's not for C style. Perhsps one per 'module' whatever a module is?

Not looking for answers particularity here although any and all advice is welcome but wondering where people go for advise on hiw to use C well. The modern C pdf referenced earlier is s good but incomplete start
498 posts
C Programming Resources/Algorithms
I disagree with suggesting K&R as anything except a historical reference. The C used there is an old version and programming practices have evolved a bit since then.

When learning a language it's always a good idea to get a copy of the spec of the version you will be using (what your compiler understands).
25 posts
None
C Programming Resources/Algorithms
Edited by hugo on
jb99
Not looking for answers particularity here although any and all advice is welcome but wondering where people go for advise on hiw to use C well.


You can see some of Casey's philosophy here:
https://mollyrocket.com/casey/index.html specially https://mollyrocket.com/casey/stream_0019.html

In the end, I feel like its about good taste and learning from "masters". One C project I take a look from time to time is https://github.com/antirez/redis for example...
Abner Coimbre
318 posts / 1 project
Founder
C Programming Resources/Algorithms
Edited by Abner Coimbre on Reason: Formatting.
ratchetfreak
I disagree with suggesting K&R as anything except a historical reference. The C used there is an old version and programming practices have evolved a bit since then.

You're aware K&R was co-authored by the original language designer with 2nd edition covering ANSI C, the most widely used and compilable language spec in history. Being an old version is a good thing. Everything that is new is explained in terms of how it adds or diverts from it, and most importantly, everything you write with it will still be more portable than anything else (wasn't it until recently that MSVC supported the remaining C99 CRT routines?). Learning the new things is straightforward.

As far as programming practices are concerned, they differ from industry, teams, and individuals, and choosing the one right for you is made easier after fundamentals are in place. I acquired them on the job, it's not a big deal. I understand K&R alone would not be enough, but it seems odd to not study C from its own creator, then move to books (or series) which use newer specs for projects today.

ratchetfreak
When learning a language it's always a good idea to get a copy of the spec of the version you will be using (what your compiler understands).

Agreed.
50 posts
C Programming Resources/Algorithms
Edited by itzjac on
Here, am interested in the Algorithms part of this question.

I am up to finding reference book about Algorithms and Data Structures, have found these two

Algorithms Fourth Edition by Robert Sedgewick, unfortunately Java all the way but perhaps it doesn't matter if the book is really well written, any one would recommend it?

Introduction to Algorithms by Thomas-Cormen, perhaps more oriented to the academic world.

Found that Sedgewick has other algorithms books in C and C++ but they are a bit older, they recommend to use the last one which is mostly Java.


I will be glad to read your recommendations.