Shop OBEX P1 Docs P2 Docs Learn Events
C & Spin translator needed — Parallax Forums

C & Spin translator needed

Erik FriesenErik Friesen Posts: 1,071
edited 2008-10-09 21:21 in General Discussion
I have been trying to learn C programming. I know how to program in spin and would like to be able to have some sort of reference that would translate somewhat and explain the differences between the languages.

Has someone done this already in some other place?

It seems like this could be beneficial to all new spin learners as well.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-10-09 02:04
    I'd focus on C++. This language is a new version of the old C, and uses many (if not all) of the old C conventions. Plus, C++ is object oriented (like Spin), while C uses procedural programming (like PBASIC). Still, if you want to stay with C you can always "upgrade" your knowledge to C++ with little effort.

    Anyway, it's probably easiest to just buy a couple of begining C (or C++) books, and learn from that. You'll be able to compare what you know to what is written, but without the older language getting in your way. If you're looking for a guide that compares the two, I think you're out of luck. First, the Spin language is relatively new and fairly limited in it's impact on the computer world, and I think most Spin publications (how many, like 3?) are focused on learning the language, not on helping you learn others. Also, although they may be similar in some ways, they do fundamentally different things: Spin is for dirrectly interfacing with electronics and working with I/O pins, while C++ is more concerned with the traditional algorithms and GUIs associated with desktop computers.

    BTW, I'm going the other way: Java -> PBasic -> C++ -> Spin
  • SRLMSRLM Posts: 5,045
    edited 2008-10-09 02:14
    I'll go ahead and post some differences between Spin and C++. I don't know what they are for C, but they should be fairly similar.

    Whitespace (CR, Tab, space) in Spin matters to associate commands together, while in C++ whitespace is merely to make it format nicely; all the association is done in other ways.

    C++ prefers to use as many local variables as possible, while Spin uses global.

    C++ is not broken into blocks like Spin

    Spin does not have a GUI system like C++ (at least not as advanced)

    C++ is much more difficult to learn, and has many more variations, than does Spin. It also doesn't have a true central authority or reference on the subject.

    C++ is not limited (in any practical way) on memory or space requirements

    C++ and Spin both have pointers

    C++ does not limit the number of Objects created, while Spin does (based on Cogs)

    C++ objects may emulate a real world object, but they don't generally interface with them like in Spin.

    C++ is more difficult to get up and running when compared to Spin

    Spin is more expensive ($100 for demo board), while C++ can be free (see the Borland or GCC compilers and IDE)

    Objects in C++ are broken into two files: a header file (.h) and a CPP file (.cpp)

    There is no version of assembly language in C++

    ______________________________________________

    I hope this helps.

    SRLM
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-10-09 02:40
    The deal is is that I am trying to learn microcontroller C, which may be the same as C++, but I don't think so.

    I am using a pic24 starter kit and to follow a path through the software is somewhat difficult.

    I have even considered sticking with assembly but there is very little documentation for usb and misc in assembly.

    Thanks for the above. Every little bit helps to bring it all together in the mind.
  • FranklinFranklin Posts: 4,747
    edited 2008-10-09 03:12
    Micro controller c will be standard c with added commands that will depend on the processor you are using and the company you buy the compiler from. The way to learn this is get the compiler for the controller you plan to use and go to the forums for that controller and compiler. Each version is just a little different.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • SRLMSRLM Posts: 5,045
    edited 2008-10-09 05:00
    You could always learn the console C version, then just downgrade it to a microcontroller type. It never hurts to learn too much...
  • hippyhippy Posts: 1,981
    edited 2008-10-09 14:49
    How different C is to Spin depends a lot on what level of C or Spin you are looking at. When it comes to USB or TCP/IP you'll be looking at some quite complex code whether it's written in C or anything else.

    If you get down to just the basics there's very little difference IMO and I would say mainly in the syntax department ( how code is actually written ), the way pointer use is coded, and the greater number of variable types that C has.

    Most Spin constructs have an equivalent in C and the same functionality can be achieved although the code may look very different as a result. I'm not sure it's that useful to have a guide to similarities and differences of C to Spin as it's really more about knowing how to achieve a result in either language.

    I'm not proficient in C, don't particularly like it as a language ( even more so for C++ ), but have had no problem in using C for some PICmicro projects. I've generally used it ( B Knudsen Data's CC5X and CC8E ) as a super-Assembler which suits me fine as I don't like the PICmicro assembler instruction set. With just a basic knowledge of C I've had some quite impressive results which would have taken much longer in assembler with all the advantages a high level language brings.

    I've not used Microchip's C ( not that keen on MPLAB other than for simulation and debugging ) and it may be worth looking at alternative C compilers if there are any which offer different flavours of C or alternative development environments. If you are using Microchip C code then it's likely that you'd be better of using Microchip tools.

    Learning any language can be difficult if you dive in at the deep end. Perhaps try some simpler things first then once you've got your foundations sorted you can build on that and more complicated constructs become simpler to understand.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-10-09 21:21
    Yeah I know I shouldn't dive in at the deep end like you say hippy. Its just that when you can proficiently program the propeller it is hard to settle for not even being able to follow the path of the program.

    Another thing I have to say is the microchips forum doesn't seem to be very helpful. There is around 70 different english forums to decide from. The parallax forum is much more active.
Sign In or Register to comment.