C++ Questions
Whit
Posts: 4,191
My son will be taking a programming class in the fall (High School). They will be learning about C++. The IDE they will use is CodeBlocks (free to download) and the book, which we have in pdf is Jumping into C++.
Can anyone share their experience? And how or is one C++ like/exactly like/or similar to other versions. I guess what I am asking is how much translation would there be between what he will learn and the Propeller C that is used for the Prop and ActivityBot documented here on the Education Team's Learn pages?
My experience is all Parallax based...and still mostly PBASIC, and Spin. I keep trying to get to C, but haven't made if past just the surface. Ideas? Comments? I think this my be a perfect time to learn and my son and I can do it together (and he can teach me a few things!).
Edit - I'd like to sneak over to the Learn and Propeller C stuff to play, but did not know if it would be confusing (a least initially).
Can anyone share their experience? And how or is one C++ like/exactly like/or similar to other versions. I guess what I am asking is how much translation would there be between what he will learn and the Propeller C that is used for the Prop and ActivityBot documented here on the Education Team's Learn pages?
My experience is all Parallax based...and still mostly PBASIC, and Spin. I keep trying to get to C, but haven't made if past just the surface. Ideas? Comments? I think this my be a perfect time to learn and my son and I can do it together (and he can teach me a few things!).
Edit - I'd like to sneak over to the Learn and Propeller C stuff to play, but did not know if it would be confusing (a least initially).
Comments
prop-gcc does have it's own libraries for the C on the Propeller mostly to handle Propeller specific hardware features or provide smaller versions of standard library functions as there is not much memory on the Prop.
It is quite feasible to use C++ on the Propeller. Despite what many rumours say C++ can produce code that is as space and performance efficient as C. In fact I have created code that uses "Spin like" objects in C and C++ and they both compiled to exactly the same instructions!
BUT. Where the problems start with C++ is when trying to use it's standard library. That is generally not possible as it's huge and generally nothing fits in the prop memory space. So things like streams "cout" etc, or container classes are not usable.
Then you want to stay away from "new" and "delete" as that gets you into memory management and garbage collection bloat. It's do able but I would not want to. Also exceptions are off the table.
Now of course your son may well be learning on a Windows machine and end up learning all about the Windows GUI API and so on, all of which is a no-no on a micro-controller.
So, in short, C++, the language itself, does not need any translation from PC to Propeller or whatever platform. But programming in C++ for the Prop or other micro-controller can be a very different experience due to the limitations mentioned above.
Just to make life more confusing C++ has changed quite a lot with recent new standards, it has many new features to make programming easier and more reliable....I hope his instructor has been keeping up with the times.
M
The Arduino guys are very good at never mentioning that fact and only documenting C++ features that work well on that platform.
Same language, very different from making a Windows app in Visual Studio.
I mention this because I agree it would be a fine thing for both you and your son to learn PropC together. Physical computing in the form of robotics is a terrific way to explore any kind of programming, and what better way to learn than to explore it as a team. It won't hurt his studies this fall, and it might just help dad!
Agreed - Robotics is great way to learn programming because you get instant "real world" feedback and it is not abstracted. We will start playing. And Yes - Helping Dad is always good!
Thanks for the "::" note too - had not notice that in the way it is typed. The answer was just a google away!
Edit - Just noticed this is post 3,001 - dang I've got a long way to go to catch up with erco!
This might be of interest to you and your son. Ive used spin2cpp to convert S2 programs into SimpleIDE C++ programs.
The first example is your Fibonacci Spiral, and the second example is the HokeyPokey:
-John
@John A. Williams - Absolutely! I had never heard of the spin2cpp! This is really cool stuff! Been researching it. Thanks so much!
Then, once you've mastered the core of the language, and should there be an interest in going further, you can always teach yourself how to write those function libraries yourself.
https://github.com/libpropeller/libpropeller
David Zemon has also released a C++ library:
https://github.com/DavidZemon/PropWare
There's a pretty good FAQ page about PropGCC:
https://sites.google.com/site/propellergcc/documentation/faq
And even some instructions on using Code::Blocks with the Propeller:
https://sites.google.com/site/propellergcc/documentation/tutorials/code-blocks
Aside from libraries, C isn't bad to learn - The complexity of it is almost entirely in the additional libraries you use (somewhat like Spin and the Obex & Propeller objects). C ships with a set of standard libraries that handle things like memory management, file or console I/O, string manipulation, etc. Those things make less sense on a Propeller than they do on a PC.
If you stick to using stuff that's for the Prop, and specifically the subset of features that are well handled by the Prop, things should go pretty smooth. If you start using things like "printf" (print formatted string) or floating point math, the code size starts to go up pretty fast because those support libraries get pulled in and they're quite large.
I agree with Mr. McComb that you should not use spin2cpp. Its use could lead to a great deal of confusion.
I know that you are a big fan of the S2 Robot and thought you would find it interesting that the S2 can be programmed in C and C++ using SimpleIDE with the modified S2 drivers (custom libraries).
When you examine my examples, do not go beyond the opening screen. Ignore the stuff between lines 20 and 27 in the Fibonacci program and lines 12 to 31 in the HokeyPokey program. After that, the code should look somewhat familiar.
John