The Crystal Programming Language Forum

Learning C, looking for recommendations!

This is (obviously) a little off-topic but since Crystal is able to interface with C much easier than Ruby is I decided I’ll finally (finally!) learn enough C to be dangerous to others :sweat_smile:

I can read it to a point and have written in it before but my level is low. I’ve tried a couple of books/courses in the past but didn’t get along with them. If anyone has a recommended tome, let me know, it’ll be much appreciated!

Regards,
iain

3 Likes

There was a talk on writing C bindings at the last Crystal conference: Real-world lessons writing Crystal C Bindings - Raw Crystal 2020 - YouTube

and it piqued my interest in learning “enough C to be dangerous” too!

But I’m in the same boat as @yb66, would love to find something out there that was more aimed at this path that Crystal helped create Ruby => Crystal => C.

One of my favorite things about Crystal is how it has sparked an interest in me to learn more about fundamental computer science and shake off some of my fears of that world.

So … I’m writing this to basically give it a +1 in case there is some dev out there that might be able to put together some learning materials on that path but just needs a little encouragement from an interested community :)

1 Like

I remember writing C in college, however I unfortunately don’t remember any of the books they used. I do remember quite clearly though that the big turning point for me at the time was when I had to write a simple file system from scratch in C. It was a lot of fun and it was a very specific challenge with enough nuance to keep me busy for a few weeks.

All that to say… regardless of what written material you find, writing some low level “thing” that is common enough to find good discussions on proper design might be a good hands-on way to learn.

BTW, I have no desire to use C anymore beyond the necessary bindings. That’s why I was so excited about Crystal. My language path went like this C => lots of other languages => Crystal.

1 Like

This is a C tutorial that I liked a lot: “Build Your Own Lisp - Learn C and build your own programming language in 1000 lines of code!”

http://buildyourownlisp.com/

2 Likes

Hey all, postmodern here, the person who gave that Real-world lessons writing Crystal C Bindings talk. When you start writing Crystal Bindings you are essentially reading a C header file and translating it’s C typedefs, structs/unions, and function signatures into the Crystal equivalents; not writing actual C programs. So you really only need to know C’s data types, how to read pointers, and how to read basic C #macros. Thankfully, Crystal provides most all of C’s primitives, so you’re probably already familiar with ints vs. uints, static arrays, double arrays, enums, structs vs. unions, pointers, etc. Any old C tutorial that covers C data types or book should be sufficient.

For reference, I first learned the basics of ANSI C via one of those “C: The Complete Reference” books, which covers the basics then goes into the stdlib. Later in university I had to use the famous K&R “C Programming Language” book, who’s preferred C syntax is kind of uncommon now days.

1 Like