2014-08-05 13:17:58

Hi all. I got the book on C from circa 1975 or so, and discovered that the programs won't compile! So, is there a better book? And is it possible to compile C on Windows?

2014-08-05 21:26:25

Unless you have a pressing reason to learn C specifically, don't.  C++ is more complex but better, if only because it now provides limited automatic memory management.  Unless you have a pressing reason to learn C++ specifically or are already a very good programmer, also don't.  That said:
The C book from 1975 is drastically outdated.  Back then, you couldn't compile its examples on a different compiler, let alone 40 years of standardization, improvements, development, etc.  Not only won't the programs compile, but updating them will be hard.  This situation is now better, in that all the major platforms implement at least C++ 03.  Most of them have implementations of C++11 (which introduced smart pointers, the limited form of automatic memory management I swear by), but C++11 is too new to find many "I'm new to C++" resources that show you its features.  The reason I and a lot of other C++11 programmers know the new features is because we are far along enough to need them, though I can make a very good argument that shared_ptr is something that new programmers should be shown immediately.  If you are on an embedded platform, you will be lucky to have C99/C++98, so I'm not going to waste time waxing poetical about C++11 until I know that you have it.  It would also be helpful to know your programming experience and background before I try to help past this post.
The two main references these days seem to be http://www.cplusplus.com and http://www.cppreference.com. Both offer links to tutorials if you poke around.  Your best bet is to Google for tutorials, imho.  If you're dead set on a book, this SO answer gives a lot of them.
Here's a direct link to a tutorial that appears to be pretty decent: http://www.cplusplus.com/doc/tutorial/
I'm having trouble finding anything that doesn't assume you already know how to program.  If this is a problem, I'm afraid I can't help.  The work I do in C/C++ these days often requires consulting the standard when I need something new; that's the only reference for the most advanced features and guarantees, and consulting it is a sign that you're probably doing something dangerous (so when I do, I immediately consider redesign possibilities).  I know it too well to pull a bunch of good learning tutorials out of my hat, basically.
C is an incredibly simple language, at the cost of having to manage literally every allocation and deallocation, having no automatic cleanup (you can get far with preprocessor magic, but I'm not even going to try to explain how I pulled off those tricks without a full blog article), having no encapsulation that you don't make yourself (no equivalent of BGT's classes, and all I'm going to say is enjoy implementing vtables), etc.  C++ gives you object oriented features and a good standard library, This latter point is arguable, but having sets, vectors, maps, hashtables, and the algorithm header is a godsend as compared to C.  In C everyone writes their own version of all the standard data structures from scratch.  My last point is this: C++ is a monster that you tame, not a programming language that you learn.
I'll help further if I can.  Specific questions would be helpful.

My Blog
Twitter: @ajhicks1992

2014-08-05 22:24:37

The definitive book on C, "The C Programming Language", now in its second edition, covers C89 and is still very relevant; you can learn later additions to the standard, most of which were either glaring mistakes or useful bits copied from C++, when you have a need for them. You can get it on iBooks, if you have that.

The tutorial I started out with was Coronado Enterprise's C tutorial which is very good for what it covers; it's also commercial. You can check out their other tutorials while you're there. The next best I have used is the C tutorial that accompanies LCC-Win32, which is also an excellent compiler to get you going generally, although of course no match for Visual C if you want the very latest interfaces.

Just myself, as usual.

2014-08-06 02:52:46

camlorn wrote:

Unless you have a pressing reason to learn C specifically, don't.  C++ is more complex but better, if only because it now provides limited automatic memory management.  Unless you have a pressing reason to learn C++ specifically or are already a very good programmer, also don't.  That said:
The C book from 1975 is drastically outdated.  Back then, you couldn't compile its examples on a different compiler, let alone 40 years of standardization, improvements, development, etc.  Not only won't the programs compile, but updating them will be hard.  This situation is now better, in that all the major platforms implement at least C++ 03.  Most of them have implementations of C++11 (which introduced smart pointers, the limited form of automatic memory management I swear by), but C++11 is too new to find many "I'm new to C++" resources that show you its features.  The reason I and a lot of other C++11 programmers know the new features is because we are far along enough to need them, though I can make a very good argument that shared_ptr is something that new programmers should be shown immediately.  If you are on an embedded platform, you will be lucky to have C99/C++98, so I'm not going to waste time waxing poetical about C++11 until I know that you have it.  It would also be helpful to know your programming experience and background before I try to help past this post.
The two main references these days seem to be http://www.cplusplus.com and http://www.cppreference.com. Both offer links to tutorials if you poke around.  Your best bet is to Google for tutorials, imho.  If you're dead set on a book, this SO answer gives a lot of them.
Here's a direct link to a tutorial that appears to be pretty decent: http://www.cplusplus.com/doc/tutorial/
I'm having trouble finding anything that doesn't assume you already know how to program.  If this is a problem, I'm afraid I can't help.  The work I do in C/C++ these days often requires consulting the standard when I need something new; that's the only reference for the most advanced features and guarantees, and consulting it is a sign that you're probably doing something dangerous (so when I do, I immediately consider redesign possibilities).  I know it too well to pull a bunch of good learning tutorials out of my hat, basically.
C is an incredibly simple language, at the cost of having to manage literally every allocation and deallocation, having no automatic cleanup (you can get far with preprocessor magic, but I'm not even going to try to explain how I pulled off those tricks without a full blog article), having no encapsulation that you don't make yourself (no equivalent of BGT's classes, and all I'm going to say is enjoy implementing vtables), etc.  C++ gives you object oriented features and a good standard library, This latter point is arguable, but having sets, vectors, maps, hashtables, and the algorithm header is a godsend as compared to C.  In C everyone writes their own version of all the standard data structures from scratch.  My last point is this: C++ is a monster that you tame, not a programming language that you learn.
I'll help further if I can.  Specific questions would be helpful.

Camlorn, can you stop going into depth about your opinions? Just debrief us on your opinion and leave it at that. I don't see what's so great about C++. IMHO, its a lot harder to use, and its very bloated. Also, not very many compilers support C++11/C++14. Plus, how would you know if you could or couldn't compile The C Programming Language's first edition examples? Have you tried it? If you've read it somewhere, don't believe it; verify it. How would you know if I was lying if I said I was 30 years old? I'm not, but still. What if I set my age somewhere else and set my age to 30 years ago (1984)? BTW, you probably could've compiled those examples around 1983, around the time microsoft began development of windows. Remember, in 1976, compilers didn't exist. Hell, we didn't have a clear vision of what binary was. All we had were little punch cards that you inserted into a machine and hoped you got your code right. That's really all we ahd. Well, along with empire building sized computers that filled up an entire room. Some of those were so power needy that one of them dimmed an entire section of lights in one of the states. I forget which one. So, again, keep your in-dept opinions to yourself, and state them in simple, one or two liners.
As for books, I recommend Practical C Programming. It goes in depth of what everything does and how it works, and I really like it.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2014-08-06 05:02:31

Er. No.  See this timeline, since apparently knowing something isn't a qualification in these parts.  C needs a compiler, so merely knowing that a book about C existed in 1975 is sufficient to inform me that a compiler must have existed for it.  And we were more than moving on from punch cards by that point, all be it not yet at the point of home computers being anywhere near common.
As for compiling the programs, he said he can't.  This is sufficient proof that something is either wrong with the programs themselves, or they were written before C was standardized, modernized, and etc.  I am sure I could get them working if I put effort into it, if only by downloading older compilers.  I would not suggest someone new to the language try to do so.  One concrete example of an archaic feature that comes to mind is the old-style function declaration, wherein you use only types and the empty () means a function taking any number of parameters.  I can exclude the compiler because those have programmers working on them who know way more than everyone I know including myself put together.  I can exclude the programmer, because this is a transcription from a book which should be expected to know what it's talking about.  Given that the first C standard wasn't published until 10 years later and we hadn't yet seen the rise and dominance of the x86 processor, it is very logical to assume that a modern compiler--almost 40 years later!--might have trouble.  It is sad that I need to spell out my logic; I know these languages and their histories as well as anyone on these forums.  It is illogical to assume that a language with no published standard and no major dialect did not change in some incompatible way in the 7 years between 1975 and 1983, so I am very unclear what windows has to do with anything.
Also note that I gave a lot of helpful info, and I feel the warning is warranted in this case.  If you have a problem with my verbosity, I don't see how quoting my post helps.  If you have a problem with me personally, just say so and have done.  I felt obliged to say something because I've seen too many programmers think that they absolutely need to know these languages, try to learn them, and give up on ever learning another language again.  I have given my warning; if king gamer222 really wants to learn it I'll help him do so to the best of my ability.  I am the last person to say that these languages are useless or don't have a place.  They do: you sometimes really do need the performance.
But obviously arguing with you is pointless anyway.  I have yet to be on a thread where you have a problem with my opinions and provide good, logical, and concrete reasons they are incorrect.  You always attack me directly instead.  Doing so is not constructive; it merely places me in a position wherein I cannot defend myself without starting yet another war.  Sigh.
I will decrease my verbosity only when people stop saying that I am wrong without being able to tell me why.  I do not mind being wrong.  I do mind being told that I am wrong by someone who can not tell me why I am wrong and simply says that I need to "try things".  If I am verbose, it is because I have great need to declare and specify my reasons; if I simply say "x is good, y is bad", that carries no weight whatsoever.  Apparently I have yet to establish any sort of credibility, despite being one of the few people to ave any success providing 3D audio whatsoever.  Maybe I just need to go write a game before people will take me seriously here; apparently all my other programming is not sufficient to show that I might just have a clue in your eyes.

My Blog
Twitter: @ajhicks1992

2014-08-06 05:04:45

Actually, it turns out that GCC won't compibe the K&R C examples. As for why I wish to learn it: that's a quest. One which will lead to ObjectiveC, then to Swift.

2014-08-06 05:07:21

If you want to also discuss bloated languages, Perl is one such example. It basically looks like a bunch of spaghetti code and half the programs rarely function, which is odd. TTYtter is one such example. It even had a warning, but I was still surprised when it crashed.

2014-08-06 07:18:03

Personally, I don't like objective-C because it makes C a lot more complicated than it already is.
I've never tried swift; maybe I'll give it a go.
Another language you might consider learning is Go, google's programming language. Here's a hello world in it:
import "fmt"
func main() {
fmt.Println ("Hello world!")
}
Oh, and camlorn, I wasn't meaning to give offense to you. I was just stating that sometimes, your verbosity, well... let's just say that you get a little carriedaway with it. Don't worry, I do that to.
KingGamer222, if you ever learn C, and are up for it, try learning flex/yacc, or, learn the Ragel State Machine Compiler. I have converted the documentation into HTML format; I hate PDFs!
I still think that Practical C Programming still stands. It is a very great book. Try reading it.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2014-08-06 10:31:56

@KingGamer: I'm surprised the K&R style code won't compile on GCC 4; I should look into that. Although, yes, you really want to learn the new ANSI declare-and-define routine, which is both more correct and clearer to read and understand.

Get "The Swift Programming Language" from iBooks, and save yourself the round trip of C. While I believe you should learn C, Swift was intended to be newbie-friendly and high-performing, and is geared up to win hearts and minds of future developers. Whether it will replace C as a system programming language is another matter, but it can work as such in the Apple ecosystem, which I still find astonishing.

Just myself, as usual.

2014-08-07 18:25:25

For those of you that think C is bad, try learning assembly. God, that stuff's confusing.

2014-08-07 21:58:25

if the goal is Swift, skip all the intervening stuff and just do it.  C will not help you learn Swift, save perhaps by making you a better programmer in general.  Swift is closer to Python than anything I know, but is still strongly typed and brings in attributes of all the other languages I know, too.
Objective-c is apparently a nice language.  I disliked it because of the verbosity and because XCode highlights every single problem I have with Mac accessibility, but nothing is really wrong with it.  While it, too, is a superset of C, you can skip right to it: you don't typically use char* and all the C libraries, as I understand, and it has some niceties like reference counting.  You need a Mac for both of these, though (sorta...you can technically run obj-c on windows, but...).
Assembly isn't worth your time unless you're coding for embedded hardware or doing some really hardcore stuff like OS development.  The modern x86 architecture is not aimed at programming in assembly anymore.  It's literally gotten to the point where your compiler can and will usually do a better job programming in assembly than you can--to get good performance out of it, you have to know about all sorts of stuff that I don't actually know myself, simply because there is no need for me to do so.  Examples of the ones I do personally know about include cache friendliness and unrolling and auto-vectorization of tight loops.
Go is an interesting language with a lot of unique features, and may not be a bad choice.  The problem with Go is that there are a few quirks that make it unfriendly to a screen reader user (whether or not a function starts with a capital letter determines if it is public is the big one here).  They can be worked around.  The big killer is that Go is a server language; nice enough to work with, but with few options for desktop libraries.  If the goal is a game, I'd suggest avoiding Go...for now.
I also dislike Perl.  It does indeed have a lot of little special cases, and at least one thing (file I/O as I recall) places very, very heavy emphasis on the difference between capital and lowercase.  Again, you can work around this.  The only language I haven't found an easy way to work around is Lisp, but the case sensitivity has semantic meaning bit is a big annoyance of mine.

My Blog
Twitter: @ajhicks1992

2014-08-08 00:05:56

I do think you get a lot from Objective-C, because even though it's its own little universe, still you will end up learning C in the process which will help you elsewhere (it's a superset) but I also don't like it because the surgery is not clean. But yeah, Swift. Swift is so, I don't know, so very what you get when you don't burden the programmer with C. smile It's really the language Apple should have had all along, but couldn't because it was dependent on C for Unix. Free yourself of C and you have got a language that promises to be a lot with a low learning curve, native object types, sensible control flow structures, nice syntax (I still prefer Tcl though), dependability and high comfort and reward with the feel of any scripting language. Definitely, check it out.

Just myself, as usual.

2014-08-08 01:57:10

I plan on getting the Swift book, but too bad Snow Leopard won't run the latest xCode.