Shop OBEX P1 Docs P2 Docs Learn Events
C++ Questions — Parallax Forums

C++ Questions

WhitWhit Posts: 4,191
edited 2015-06-13 11:34 in General Discussion
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).

Comments

  • Heater.Heater. Posts: 21,230
    edited 2015-06-11 05:25
    C++ on the propeller uses prop-gcc which is the GCC C/C++ compiler modified to generate Propeller instructions. As such it is very standards compatible.

    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.
  • WhitWhit Posts: 4,191
    edited 2015-06-11 15:11
    Thanks for the detailed answer Heater! What you've said makes sense to me and your answer helps a lot... and will help me more quickly recognize issues should they come up.

    M
  • Heater.Heater. Posts: 21,230
    edited 2015-06-11 17:05
    I forgot to say. The famous Arduino is programmed in C++.

    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.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2015-06-11 17:38
    Whit, Both the Arduino and Propeller C are fairly insulative of the "nitty-gritty" of the underlying C/C++, in that most of the heavy lifting is done by libraries. What you program in is a simplified syntax, while keeping open the potential to write more robust code if you really want (or need) to. I would say PropC, with Andy's learn libraries, is the easier C language to start with, though others think it's best just to jump in feet first. In any case, PropC teaches all the fundamentals of well-structured programming, conditionals, assigning and using variables, data types, and all that. Armed with this knowledge, it's an easier jump to C++. Code::Blocks (you'll discover that double semi-colon means something!) is a nice system.

    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!
  • WhitWhit Posts: 4,191
    edited 2015-06-11 17:54
    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!
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-06-11 18:01
    I've found the Arduino platform great for learning C. Ditto Propeller C. Like others have said above, I think it is because they insulate you from the underlying code. It is quite possible for instance to write large programs without ever using a pointer (the mysterious * in C, which I have never truly understood). By keeping things simple there is a style of coding I've found which makes it relatively easy to move between vb.net, Arduino C and Spin.
  • WhitWhit Posts: 4,191
    edited 2015-06-12 05:45
    Thank Dr_Acula - Keep it simple - always good advice.

    Edit - Just noticed this is post 3,001 - dang I've got a long way to go to catch up with erco!
  • John A. WilliamsJohn A. Williams Posts: 8
    edited 2015-06-12 12:27
    Hi Whit,

    This might be of interest to you and your son. I’ve 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
  • WhitWhit Posts: 4,191
    edited 2015-06-12 13:58
    This might be of interest to you and your son. I’ve used spin2cpp to convert S2 programs into SimpleIDE C++ programs.

    @John A. Williams - Absolutely! I had never heard of the spin2cpp! This is really cool stuff! Been researching it. Thanks so much!
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2015-06-12 15:45
    I'll make the ever-so-respectful suggestion you refrain from using code conversion software until you have a couple of the Learn lessons under your belt. These tools are great for porting over code, but they aren't great at conforming to a specific learning style that may be presented to you. That can cause a lot of confusion. Specifically, what the Learn tutorials have you do, and what a spin2cpp conversion tool outputs, are miles apart. As noted earlier, the Learn examples use a set of custom libraries that encapsulate common functions. So -- unless you want to -- you don't hand-code a button press function. You just use the function that Andy wrote.

    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.
  • SRLMSRLM Posts: 5,045
    edited 2015-06-12 15:48
    I like C++ on the Propeller since it allows the use of professional tools and techniques to make programs. I even built a C++ library to help out:

    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
  • JasonDorieJasonDorie Posts: 1,930
    edited 2015-06-12 17:19
    I've found Prop-C to be quite easy to use (given that I already know C/C++) and the compiler produces pretty efficient code.

    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.
  • WhitWhit Posts: 4,191
    edited 2015-06-12 19:02
    Thanks Gordon, SRLM, and JasonDorrie! What is making me feels good is that whatever we learn will not be lost. We are going to start exploring and having fun.
  • John A. WilliamsJohn A. Williams Posts: 8
    edited 2015-06-13 11:34
    Hi Whit,

    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
Sign In or Register to comment.