Learning C --- Book and PDFs versus on-line tutorials
LoopyByteloose
Posts: 12,537
Just to be clear, I am interested in ANSIi C as presented in the 2nd edition of "The C Programming Manual" for use on the Propeller.
Regardless of whether you chose Catalina C or GCC (both support ANSI C), I am finding that for myself that the on-line tutorials are rather dubious. So I have relied on texts and PDFs for learning. And I particularly enjoy reading some rather old material written by the original developers of C. I think that they were great teachers and they tend to express a lot of insight into what they really wanted the language to do.
Whether true or not, I get the feeling that on-line tutorials tend to recycle other peoples work and often don't rigorously cover all aspects of learning a language. Added to that I am find a lot of searches for learning C on-line divert to C++. And C++ is a different much larger topic. It is just as easy to get diverted to C#, Ojective C, and so o. If one must search on line, it might be best to search for "ANSI C" and not just C.
Is anyone else a big fan of Richie and Kernighan?
This old stuff was oriented toward text based programming as GUI and Windows did not exist at that time. Is that a strong point or a weakness for you?
Do you find references to Unix rather daunting as a Windows user, or is that not an issue?
http://en.wikipedia.org/wiki/The_C_Programming_Language
http://cm.bell-labs.com/cm/cs/cbook/
Feel free to post links to sites that support the C language as it can be used on the Propeller.
Regardless of whether you chose Catalina C or GCC (both support ANSI C), I am finding that for myself that the on-line tutorials are rather dubious. So I have relied on texts and PDFs for learning. And I particularly enjoy reading some rather old material written by the original developers of C. I think that they were great teachers and they tend to express a lot of insight into what they really wanted the language to do.
Whether true or not, I get the feeling that on-line tutorials tend to recycle other peoples work and often don't rigorously cover all aspects of learning a language. Added to that I am find a lot of searches for learning C on-line divert to C++. And C++ is a different much larger topic. It is just as easy to get diverted to C#, Ojective C, and so o. If one must search on line, it might be best to search for "ANSI C" and not just C.
Is anyone else a big fan of Richie and Kernighan?
This old stuff was oriented toward text based programming as GUI and Windows did not exist at that time. Is that a strong point or a weakness for you?
Do you find references to Unix rather daunting as a Windows user, or is that not an issue?
http://en.wikipedia.org/wiki/The_C_Programming_Language
http://cm.bell-labs.com/cm/cs/cbook/
Feel free to post links to sites that support the C language as it can be used on the Propeller.
Comments
I used my original K&R book examples with PropGCC, and in most cases it worked as expected. The problem, IMO, is when you move into using the Propeller specific material, it is a whole new ballgame, the examples that are available are very terse, and just by reading the K&R book, it is NOT going to get you where you want to go, at least it's not working for me.
Generally speaking about the online material, you are right, it is a rehash of exiting material. You just might have to go to a bookstore and BUY a book that you think is best for you. Off hand, I do not have any suggestions for which book to purchase.
Ray
I highly reccomend Practical C Programming and Mastering Algorithms with C
http://www.amazon.com/gp/aw/d/1565924533/ref=mp_s_a_1?qid=1349182962&sr=8-2
http://www.amazon.com/gp/aw/d/1565924533/ref=mp_s_a_1?qid=1349182962&sr=8-2
these two books cover the newer ISO standard ANSI C and practical C is set up to teach you good readble C programming from the begining I own alot of C books, and short of taking the C++ classes at gameinstitute.net for a few hundres bucks i think these are going to be the best and clearest written teach yourself books out there although im sure K&R is great too, maybe give these two books a looke over, if they made good seanse to a 15 year old they w be good enough for any seasoned coder
With hobby electronics, it is not just about programming the microcontroller that one must know about. There is a big world of add-on devices that come with SPI, I2C, RS-232 or some other form of interface. And sensors and motor controllers all can have a different approach to I/O.
SPIN acquired a rather huge OBEX of all these items. The BasicStamp introduced a lot of this info on a case-by-case basis with example code. I am not sure what is being done for C on the Propeller.
C in its purest form, doesn't consider the existence all these items, it expects the OS and standard libraries to provide solutions without lowest level details. So yes indeed, it is a whole new world when one starts to apply C to any microcontroller, including the Propeller. The Propeller just makes it all the more interesting by having 8 Cogs.
The core concepts of a Standard I/O that manipulates ASCII and a file system for storage are nearly non-existent in microcontroller applications. And in many cases, text is not a useful feature as timing and control are the primary design objectives. After all, microcontrollers generally are configured without an OS scheme, don't have text editors, and so on.
But still, I can't seem to Google for 'C tutorials' without getting diverted to something newer and rather useless for the Propeller. Ironically, Arduino tutorials seem to be the closest help for project specifics in C that can be used on the Propeller.
there is lots of incredible code out there done in C without using the standard library. thats what really intrests me. the first project i did in x86 asm was a simple bootloader wich was a pita getting through the a20 gate and in to protected mode. i later found a huge site called the osdev wiki wich has tons of tutorials and pet os projects, it was on that site i saw a bootloader like mine done in pure C and wow.... its such a skill to code that way.
i personally came to the prop excpecting to use C and learn PASM bah at spin but ive gradually excepted that spin is a great way to explore the props architecture and will make PASM alot easier to learn. Lets face it ASM is about understanding an architecture more so than commiting an instruction set to memmory. I feel once one has a grip on PASM they will truly be able to use gcc as a shorthand for assembler, which will provide a fast powerfull coding style but with productivity speeds closer to spin than pasm, K&R wrote C for this same task when developing unix.
i guess my point is while learning prop gcc one should also learn pasm and understand how to utilize c with no standard library to maximize the power and speed of your programs
The fact that K&R and other C texts have nothing to say about graphical programming is a bonus. They are teaching the language not some GUI library system which may or may not exist on your machine and is out of scope for such a book.
Also the text based processing is actually usefull work not just making pretty buttons on the screen. The methods learned are invaluable.
The reference to Unix should not worry anyone. Most of what you need for I/O, file handling, etc, is contained in the C standard libraries and available on Windows as well as Linux and any other OS that supports standard C.
Loopy: Not quite. C in it's purest form is used to write the operating system:) Think Unix, Linux, BSD, and probably a bunch of others. So you might like to think of using C on the Prop in the same way, I have a processor, I have a language, I will use the language to create all those hardware drivers and possibly a skelton OS to tie it all together. The result may well support the standard I/O and file system that the C standard libs expect but were not there when I started. Actually this is what the propgcc guys are up to.
You might also find that for maximum performance it is better to write your code differently on different architectures. For example it is an old practice to unroll loops to increase performance by getting rid of the looping overheads and just doing the work repeatedly. Well what if your processor has a cache? Now you might find that an unrolled loop is bigger code which does not fit the cache. All the resulting cache loading and unloading may well slow you down and a normal loop that fit's in the cache would be better. This is certainly ture of propgcc with its FCACHE mechanism.
The second edition K&R is ANSI C.
EDIT: Is see heater already pointed that out.
The C Programming Manual, 2nd ed. is a nice small text that reads well. And it can be carried with you as it doesn't weigh 5 times more than your laptop.
http://www.amazon.com/Dissection-The-Essentials-Programming-Edition/dp/0201713748
http://www.gameinstitute.com/package.php
They also have an electronics section with game consoles and robots! This is acually how I found the propeller Andre LaMounth has some classes there, including the game console development class.
Im pretty sure this isnt what your looking for but like I said if you enjoy writing games, this is a good good program although exspensive you will learn alot, the first c++ classes are all console/text based in book 1 and book 2 is windows GDI based applications. The program use to be 300 but now the srt up is way different alot cheaper it looks like
I'm thinkin' Looppy wants to stay away from C++, C#, ect. He is interested in plain basic ANSI C.
You guys tend to talk jargon that is too deep. It is like chatting on about twin overhead cams with fuel injection and a blower when the other person just wanted to know what a camshaft is. All that stuff is neat and wonderful -- after you learn the basics.
What are the minimum requirements needed to run "C" from a serial terminal.
My props are mostly built on plugboards. They have:
1. USB serial. Mostly using TeraTerm at 115200 baud.
2. 256Kb or 512Kb EEPROM
3. Standard SD-Card, probably can use micro-SD.
4. No video
I use them mainly as controllers. Been doing FemtoBasic, Spin, and now PropForth.
I really want to try C, not C++.
So what do I need, what is recommended.
Duane J
Hi Duane,
If your serial port is on the standard pins (30 & 31) and your clock is a 5Mhz crystal, you are ready to go with Catalina. Just download Catalina 3.8 and install. Then open a Catalina Command Line window (installed in the Catalina program group) and enter the following:
The parameters are important - the -lc to the catalina command means to link with the standard C library, and the -i on the payload command means use interactive mode so you can see the output (which will be sent to the serial port).
If you need to "tweak" anything (clock or pin settings etc), just edit the file Custom_DEF.inc in the folder C:\Program Files\Catalina\target
Let me know if you have any problems.
Ross.
It seems that the above saying that I need a larger than normal ROM and an SDcard interface to run Catalina C on the Propeller. I thought that all versions of C, both Catalina C and GCC would operate with the minimal Propeller configuration -- though I do admit that added ROM and a file system on an SDcard would make many more ambitious C projects viable.
Or is it just a 5mhz Xtal and a standard Propeller/ROM configuration?
I do realize there are a variety of Large Memory Models or LMMs that people have proposed or created. If would be wonderful if some suggested standard configurations were proposed to go along with them. Not everyone can buy leading edge chips from the USA, using some older and more available SRAM might be a good one. And of course, all of you that have Propeller Boards with proven C usefulness should get a mention.
Problem was that compiling C to LMM code meant that you soon ran out of HUB space as all instructions are 32 bits wide.
Now they both have the capability to compile to a compressed instruction set (CMM) which means things run at more like Spin speeds and are more like Spin sized.
Hi Loopy,
Catalina does not need anything other than a Propeller to run. The default configuration (referred to as the CUSTOM configuration in the Catalina documentation, and defined in the file Custom_DEF.inc) assumes a 5Mhz crystal and a serial port on pins 30 & 31 - but even those defaults can easily be changed. I don't think you even need an EEPROM if you intend to load your programs serially (although I've never tried to run a Propeller without one).
As for LMM, there is no standard for this, nor is there ever likely to be - the requirements for each language that uses LMM are different. But if you are just intending to learn C, I would not recommend using LMM anyway. The only advantage of LMM is speed, but you don't need that, so use CMM instead - CMM programs are much more like Spin programs - i.e. the CMM kernel is more like the Spin interpreter, and the CMM code sizes are much more like Spin code sizes. This means you can run interesting programs without running out of Hub RAM.
Catalina has complete support for CMM, in that any program that compiles and runs using LMM will also compile and run using CMM (note that the reverse is not true, as they will often run out of space!).
Ross.
It seems that just two have been mentioned.
"Mastering Algorithms in C" and "C in a Nutshell"
My problem is that if I buy directly from OReily, they offer buy Two and get One FREE. I am leaning towards adding "Practical C", but I'd like to hear from youall. They even include free shipping in the USA for them.
Hi Loopy,
If you can already program in any language, and just want to learn C, then I'd strongly recommend just spending your hard-earned money on a copy of K&R C (make sure it is the second edition - the ANSI C edition). Nothing else comes close as an authoritative C reference, and it's also just a well written book that has stood the test of time. It tells you exactly what you need to know, and doesn't waste your time with lots of Smile that you don't need to know.
If you already have K&R C, and are just looking for more example code, there are plenty of free tutorial sites on the internet. Any C code that is true ANSI C will compile under either Catalina or GCC with little or no trouble.
Ross.
The motivation behind this thread was that several people have just suggested to other new learners that there are lots of good C tutorials on-line and I have not found that to be true. If fact, I suspect really good writers have grown weary of publishing for free on the web and post less that in earlier years.
I could order a text unrelated to C from OReily as my 3rd choice, but you really can't buy just two books - it is ONE or THREE unless you are of a sub-human IQ.
Book purchase are alway a big deal for me as I have to pay shipping to Taiwan. Buy more tends to reduce the shipping cost on a per item basis. But the outcome is often that I pay about double what you do in the state. In this case, I now could buy the OReily ebooks and avoid that cost. But I like my texts.
The power and frustration with C (for me at least) are the libraries, directives, attributes and other such additions that you need to supplement and describe your program so it uses the hardware underneath it effectively. This is what knocked me off the tutorial horse and is making it so hard to climb back on. There is much information of a somewhat esoteric nature that needs to be documented for the PropGCC implementation.
It may be second nature for an old C programmer to know that you need to declare a function as STATIC _NAKED_ _WINT32_ _FRIDAYS_ONLY_ with a stack frame of such and such a type pointed to by the second parameter in the cog_start after you first re cast it as pointer to some other type.....this either needs to be documented, easily found in the libraries or learned through experience. No generic C text or tutorial is going to help with this.
Learn the C basics and then start looking at the PropGCC libraries to see what is out there and try to understand it. Play with it and ask questions, and then determine which of the answers you get is correct. As with a lot of programming issues, there can be multiple ways of doing the same or similar things.
There's a big leap from "Hello World" to creating multi-cog embedded programs using PropGCC on the Propeller.
At least that's where I was/am stuck in the quagmire.
'Mastering algorithms' is a rather ambitious but interests title as well. But the consensus seems to be pointing towards just get into the programing and ask for help along the way.
I'm not all that familiar with PropGCC, but If it really requires all these bizzaro "adornments" and complexities just to get a multi-cog program running then I suggest you use Catalina instead. Catalina takes a different approach to PropGCC, by hiding all the propeller platform complexities in a "target" that is completely divorced from the C programming language - just like it is supposed to be. Once you have a working target, you just program in C. Yes, if you want to use Propeller-specific functions like "coginit" you will need to pass the correct parameters - but this is all documented, and working examples are provided - most of them are under a page long.
For instance, here is a Catalina program that runs a C function on multiple cogs (up to 7, depending on what other plugins are loaded - it just keeps loading them till it runs out of cogs):
No quagmire here!
Ross.
This might be useful for you.
http://upload.wikimedia.org/wikipedia/commons/0/07/C_Programming.pdf
C is actually a small and simple language that you can learn in a short time.
If you have someone that is a good C programmer that you can ask questions of
then picking it up will be, of course, much easier.
I saw an online book called "C Made Difficult" that was quite thorough and was
geared toward learning GCC. If I remember correctly it is free. I did a Google but
could not find it just now, but I am certain It is out there somewhere.
I prefer compiled languages but Spin can be used to create great things with the
Propeller. I am amazed that it is so incredibly tiny.
I don't care for some of the C shorthand that is commonly used.
I like things to be so straightforward and simple that a non-programmer
looking at your code can get a pretty good idea how it works.
(eschew obfuscation) lol
Good luck, I'm sure you can learn C. If I can use it anyone can.
GCCorGTFO
Ross.
You wouldn't happen to mean this on line book "Learn C the Hard Way" http://c.learncodethehardway.org/book/ It's most excellent.
It's by Z.A.Shaw who has a lot of other interesting programming materials here http://programming-motherfucker.com/become.html
You will have to ignore the bad language there is nothing actually bad there.