But on a less sarcastic note, the "in easy steps series is good for setting things up", the "head first" series is (from experience) total garbage, and ive never read a book by the other author... good luck man
... yet here I am reading this thread without seeing any alternative suggestion. K&R2E has stood the test of time teaching the vast majority of our kernel developers from the grounds up without significant variations from the standards... where's your alternative? Every alternative I've seen has either contained factual errors (let's try to avoid those, eh?) or not had any exercises at all, exercises which need I remind you are proven to be far more effective at testing knowledge than regurgitated theory alone...
Yeah just understand that c doesn't do you any favors. It's not python where there is a handy Sandy function for every thing you need. Good luck. It's worth learning.
The major issue with C that doesn't exist with Ruby is referred to as undefined behaviour. The gist is that your one implementation is not representative of all implementations, thus some implementations may behave quite differently to yours (when you utilise undefined behaviour, that is)... in ways that are subtly devastating... this explains serious bugs like buffer overflows, race conditions and uhhh... perhaps you've heard of heartbleed? Well, yeh, people have ended up in court over stuff like this. Best beware, you want to avoid the undefined behaviour...
In C you roll your own most of the time, but that doesnโt mean there arenโt 3rd party libraries that you can use. It is just that most of the time C programmers would roll their own because they canโt rely on a 3rd party to be truly portable. Rolling your own, and the fact that C makes every step explicit will give you an insight into just how much CPU and memory the function will use.
I don't have any book suggestions but once you pass the basics of syntax, variables, functions, etc spend some time really understanding how C works from the compilation steps, the stuff that happens before main, and C's memory model. Everyone seems to skip over these concepts but they will make more advanced topics like pointers and data structures much much easier. Make sure you understand the preprocessor, the compiler, and the linker and what each does (at least at a high level). One you understand that learn about memory allocations and the stack, heap, and (if you're doing any kind of embedded work) initialized vs uninitialized memory. Oh, and have fun!!
Oh man... coming from someone who has at least completed the first three phases of translation (which isn't much, mind you)... I can see this person here barely (if at all) grasped the fundamentals that are the semantics of the language. I wonder why someone would want to make themselves seem more knowledgeable than they are? Before we go any further... in standard C there is no stack and there is no heap... and the value of any uninitialised variable (not including the implicitly initialised, which are of course initialised) is considered indeterminate, regardless of whether the environment is hosted or freestanding (is that what you meant when you wrote "embedded work"?)... That ought to say enough... but to be clear on this, I've only completed three of the eight phases of translation that are necessary, so you probably shouldn't consider me an expert, either... (basically I completed only just enough to be able to authoritatively respond to this kind of person)
Rather I prefer to say... rebuild translation phase 1... then translation phase 2... then translation phase 3... then phase 4... K&R2E actually kind of requires that you (attempt to) rebuild one of the more complex parts of translation phase 3 in ex1-23, hence the reason it comes commonly recommended. That exercise itself makes the entire book a gem worthy of study.
C Programming Absolute Beginner's Guide (3rd Edition) by Perry and Miller is good and its definitely not as dry as K&R if you're just dipping in to C. I did find an issue mentioned in this post. Good Luck
Donโt be afraid of memory management. Believe it or not, even with GBs of memory every byte still matters.
If you malloc remember to free. Always check the return of malloc, and remember to set your pointers to NULL after you free the memory they point to.
Use static analyzers to help you find memory leaks, undefined behavior and other gotchas.
Compile with different compilers to ensure the correctness of your programs and that you arenโt relying on a bug in a compiler or undefined behavior that may be defined in one particular compiler.
Start simple, write small modular programs that can be composed into bigger programs, it is the UNIX way and it will keep you sane.
12
u/jeddit999 Feb 12 '19
Get a refund and find a copy of K&R C free on the internet... https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.dipmat.univpm.it/~demeio/public/the_c_programming_language_2.pdf&ved=2ahUKEwidjvjHrrXgAhXL4IMKHTX-B3QQFjAAegQIAxAB&usg=AOvVaw0ulDzLvk3JWdexch9bu4hF
3
u/jpow07 Feb 12 '19
Yeah just understand that c doesn't do you any favors. It's not python where there is a handy Sandy function for every thing you need. Good luck. It's worth learning.
2
u/TraylaParks Feb 12 '19
This is by no means a beginner book, but it's one you might want to pick up as you progress. It is excellent ...
https://www.amazon.com/Expert-Programming-Peter-van-Linden/dp/0131774298
2
u/childintime9 Feb 12 '19
Go to a university site and find some slides/notes and the course program and follow that.
I doubt you speak italian, but if you know it I'll pass you some material
2
u/AlienAlmonds Feb 12 '19
I don't have any book suggestions but once you pass the basics of syntax, variables, functions, etc spend some time really understanding how C works from the compilation steps, the stuff that happens before main, and C's memory model. Everyone seems to skip over these concepts but they will make more advanced topics like pointers and data structures much much easier. Make sure you understand the preprocessor, the compiler, and the linker and what each does (at least at a high level). One you understand that learn about memory allocations and the stack, heap, and (if you're doing any kind of embedded work) initialized vs uninitialized memory. Oh, and have fun!!
2
u/rakanalh Feb 12 '19
Try re-building existing tools such as ls, grep, find... the process will help you pick up the language steadily
6
u/ooqq Feb 12 '19
by reading this book instead
https://images-na.ssl-images-amazon.com/images/I/41%2BbFKtFHjL._SX405_BO1,204,203,200_.jpg
4
u/[deleted] Feb 12 '19
Yes, let me borrow those :(. I am also learning, people say get "C: the modern approach"
3
u/[deleted] Feb 12 '19
C Programming Absolute Beginner's Guide (3rd Edition) by Perry and Miller is good and its definitely not as dry as K&R if you're just dipping in to C. I did find an issue mentioned in this post. Good Luck
2
u/kcbb Feb 12 '19 edited Feb 12 '19
https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html
https://github.com/kusti8/LearnCKR/blob/master/The%20C%20Programming%20Language%20-%202nd%20Edition%20-%20Ritchie%20Kernighan.pdf
2
u/puhtar Feb 12 '19
A Book on C
2
u/[deleted] Feb 14 '19
Donโt be afraid of memory management. Believe it or not, even with GBs of memory every byte still matters.
If you
mallocremember tofree. Always check the return ofmalloc, and remember to set your pointers to NULL after youfreethe memory they point to.Use static analyzers to help you find memory leaks, undefined behavior and other gotchas.
Compile with different compilers to ensure the correctness of your programs and that you arenโt relying on a bug in a compiler or undefined behavior that may be defined in one particular compiler.
Start simple, write small modular programs that can be composed into bigger programs, it is the UNIX way and it will keep you sane.