What exactly is C/C++
LoopyByteloose
Posts: 12,537
I am reading ANSI C in depth and have tried to ignore pursuit of C++ at this point on the learning curve. But I see Parallax has created a compiler for the Propeller that is C/C++.
Frankly, I'd prefer to first learn C and later comprehend C++ as the need arrises. But I begin to wonder what is going on here. I am very comfortable now with reading ANSI C and understanding how it relates to both computers in general and microcontrollers. At times, I tend to feel programmers can be an extremely nuanced nusance and fear the C++ is one of those occasions.
So can one explain if there is a real need to acquire a precise understand of C++ in order to use C with the Propeller or is the C/C++ indicative of the learner being able to choose either C or C++ according to their abilities and ambitions?
Frankly, I'd prefer to first learn C and later comprehend C++ as the need arrises. But I begin to wonder what is going on here. I am very comfortable now with reading ANSI C and understanding how it relates to both computers in general and microcontrollers. At times, I tend to feel programmers can be an extremely nuanced nusance and fear the C++ is one of those occasions.
So can one explain if there is a real need to acquire a precise understand of C++ in order to use C with the Propeller or is the C/C++ indicative of the learner being able to choose either C or C++ according to their abilities and ambitions?
Comments
-Tor
So if you don't need or don't like all the scope and permission verbosity of C++, you should be able to get by with just using C.
C++ is flexible. C++ can be complicated "large embedded systems" used in controlling SONET/STM switched optical networks (backbone of world communications). It can also be as simple as the chopped language (Wiring/Processing) used with Arduino. Wiring is essentially C++ for the rest of us. Nothing keeps a C++ program from adopting the same ideas except will and work. Of course C++ is a very long, thick rope that you can get quickly tangled in (and hung), but with good guidance, it's cake.
Spin is a very nice analog to simple C++ once you get past the small syntax differences. Actually Eric, who is very talented, wrote a Spin to C++ translator. The translation is easier mainly because C++ uses objects too.
The same could have been done for straight C, but the coding method would have to be different. C++ can be mimicked with C pretty easy if you know both languages. C++ just standardizes what is possible with C regarding objects without being so ugly. C++ syntax does make inheritance (and other things) possible that are not easy to do in straight C. Straight C is generally a very disorganized language where global scope of functions cause all kinds of problems. If all you need to do is blink an LED, then you will never see these issues in C.
Some folks will tell you to learn an object oriented programming language (OOP) so that you can use C++ effectively. After using C++ for decades I don't really believe that is necessary despite statements like "but that's not really C++" which is valid to a point, but mostly irrelevant. Inheritance for example is a valued OOP concept in C++ and Java. Inheritance (and other things) can be difficult to swallow if you've never heard of it, but it's a super easy concept once you've had a simple explanation and a chance to interact with a teacher about what's happening.
So what exactly is C++? It's an extension of C with good organization, and it is a joy to use with the right guidance. Of course there is a time and place for everything, so C++ is not an answer for every problem. Open minded users will really enjoy some of the C/C++ examples and guidance Parallax has to offer when it's published.
I have not yet looked at how SimpleIDE invokes the compilers though.
-Tor
A long thick rope of ... cake...
Good enough for me. Sold!
I believe it is possible to understand C and most of the libraries that come with it in a week or month or two.
However I do not believe there is anyone alive who understands the full impact of C++ and all the libs that come with it.
Spin is a bit like a typeless Python without a dynamic memory allocator. Which means it is conceptually similar to C++ using only static allocation of objects. The Arduino libraries use C++ in exactly the same manner, so I would imagine that would work well on the Propeller as well.
What I learned is that just about anything in C++ is a pointer, especially when you need something else...
I did learn to ALWAYS create the 'destructor' at the same time as I created a class, though.
Anyone want to buy Watcom C/C++ V11.0 compiler for DOS/Windows and OS/2?
Complete with all manuals...
(Yeah, the version that never really worked on OS/2... Should really take a look at Open Watcom soon...)
For me, it is a way of breaking out of the 32k limitation of the propeller chip. C lets you write huge programs. It also lets you do things you can't do easily in Spin, like reload cogs fifty times within a program.
That is a good idea. You could start with Catalina, which is C89. Or start with GCC but just use C syntax, as C is a subset of C++.
These observations are at the core of what I wanted to know. It is because C is easy to comprehend that I see it as the first step towards C++.
I have tried Java, Python, and other OOP languages - but they certainly are vast and seemingly abstracted from the machine level of micro-controllers. The terminology becomes somewhat confusing and overwhelming. Examples begin to have the look and feel of a text on chess openings - useful for experts, but not the whole game for the beginner. I don't have a lot of comfort with all that abstraction, though I do understand that this approach allows the rather vast programs we are using today.
The main point here is HOW the new learner is going to come to terms with SPIN or GCC on the Propeller. I am very happy to hear that C as a separate compiler so one does not have to tweak C++ in mysterious ways to have it provide a 'virtual C compiler' of some sort.
I am in no rush to use the SIMPLE IDE or C on the Propeller as I have plenty to do and learn. I just wanted to be assured that the C/C++ really meant that C was a valid alternative entry point and not just a subset of C++ in this context.
thanks all. Hopefully the SIMPLE IDE will live up to and excell beyond its name. I've looks at a lot of other IDEs that are so complex that they exceed the languages they support in documentation and demands for study.
Hi Loopy,
I'd probably recommend you plan to move from C to Objective-C instead of moving from C to C++. Although I would also contend that in the embedded space (which is where we are) there is a real need for moving from C to anything at all .
The TIOBE programming index tells an interesting story about these (and other) languages:
The TIOBE index shows that the popularity of both C++ and Java has been in fairly consistent decline over the last 10 years. The index shows C as overall stable or even on the increase over the last few years. It also shows C# and Objective-C as the new "up and comers" - but keep in mind that this is a general "across the board" index, and some of these are very platform- or application-specific languages - i.e. one is popular only on OSX or the iPhone, and the other is popular only on Windows.
If you could see the same type of graph restricted to the embedded space (I don't know of an equivalent - if anyone does, please post it), then I think Java, C++ and C# would all drop off even more dramatically - there was a flurry of adoption when these languages were fairly new, but people have realized over time they are inappropriate for low-level embedded work. But both C and Objective-C would show even bigger increases - C because it remains the only "universal" low-level language (i.e. it is supported on all platforms, and is reasonably efficient on all of them - even on tiny micros with a few kilobytes and a few kilohertz) and Objective-C because of the current popularity of the iPhone (where you have hundreds of megabytes of space available and hundreds of megahertz of processing power).
Someone said elsewhere on this site that we may soon see only two general-purpose processor architectures - Intel and ARM. I suppose it is possible we may soon only see two general-purpose languages - and this graph shows there would be a good case for saying this might end up being C and Objective-C.
Ross.
C is the latest addition as I can now see how close to Assembly language it is and why it is abstracted in the way it is. Beyond C, I am not sure I'll ever get into C++ or Objective C or whatever. It has taken a few years to sort out what the role of various compilers are and why so. With relatively small chips, knowing you can exploit Assembly is a much higher value than with desktop systems in Linux, Windows, or Apple.
With microcontrollers, there are quite a few advantages to get down to Assembly language as one in generally not trying to drive large data processing projects or sophisticated graphic or interface a wide variety of tasks over the internet. But one does often need to squeeze utility out of every register and every pin.
I've tried to learn Java, but the documentation is overwhelming and while every author claims OOP is easy - their jargon soon obscures the presentation. Similarly, I have read Python in the depth and though that seems more appealing to me than Java, it too gets off into regions that presume one knows why they need and what they want to do with tuples, and such.
I am sure there are people that will greatly enjoy C++ on the Propeller as they have already mastered it and have higher ambitions. They might like Objective C as well. I am just not at that point and dislike reading and rereading huge tomes about any given computer language.
So it seems that there is a new Objective C. I'll keep it in mind, but at this juncture I am intent on ANSI C - either Catalina or Propeller GCC. I have no great ambition of bolster a resume or set the programing world ablaze with glory. I'd just like to feel that I have a reasonable working knowledge.
I am happy Simple IDE is going to allow me to remain in a Linux environment as these days I rarely go to Windows of any sort unless I want to program a BasicStamp or and SX chip. Visual Basic is something I try very hard to ignore.
I suppose that one could divide the programing world into 'macro-programing' and 'micro-programing'. The macro-programing requires big languages with big tool sets for ambitious projects, whilst the micro-program requires fitting tight constraints of spaces, resources, and timing. I am more interesting in the latter.
As an aside, I'm not happy about there being three proprietary successors to C++ (Java, C#, and Objective C). They lock apps tightly to their respective platform and are bad for software vendors and consumers. Great for platform vendors which is why they are doing it.
Ha! Might I suggest we get back to ADA? A language designed for exactly that. There is ADA for little AVR's so why not?
The TIOBE index is interesting. Java is shown to be in decline Objective C has been ramping up since 2009. I might speculate the rise in Objective C is due to the widespread up take of iPhones and such. BUT then Android has also been a hugely growing market so where is the corresponding ramp up in Java? Well, thing is they never call Java on Android "Java". Perhaps all the job posting and such analysed by TIOBE are just saying "Android developer".
ADA? Gawd.............. programers always have something they are curious about. I just wanted to make sure that C and C++ were not clumped together on the Propeller's compiliers as references to C/C++ and GCC are confusing.
also if you ever built something like a software finit state machine every thing can be broken up into litte objects or states and fed through. things like this i cannot imagin doing in a non oop language.
Nothing wrong with ADA...
Handles multitasking, pretty well platform-independent(you ned to recompile, but unless you've been a naughty boy, that should be painless), handles garbage collection, and allows you to create such useful functions as '>', '+', '-' and so on for any custom datatype you can imagine...
Used ADA on VAX-VMS in 90 - 92(School computer) and in the evening used Janus ADA on my PC.
Beause VAX ADA didn't have a 'long integer'(The Integer type was 32bit instead of 16) I had to add a type definition to create a Long Integer, and REM it out when I worked at home.
Java was supposed to be a portable systems programming language, but the only major area where it caught on was server side web application development. Around the mid-2000's people figured out how to run other languages (e.g. Groovy, Jython, and JRuby) on the JVM. Web development is essentially a text processing problem and those languages are better suited to the task than Java, so interest in the web development community has been shifting to them and away from Java.
Android's version of Java is nearly a complete redo with a register based VM and different API's. Oracle sued them and lost because Google was fairly aware of the potential for getting sued after the Sun Microsoft debacle.
True enough, and if the HTML5 people have their way it might actually be useful for application development. It's also the only one of the bunch that is portable and standardized.
Not sure what you mean. C++ has no automatic garbage collection built in. Except for objects created on the stack I guess.
I always liked this particular piece of marketing non-logic.
Java is portable provided you implement a Java virtual machine for your target.
You cannot create that virtual machine in Java.
You have to use a systems programming language, like C or even ASM, to do so.
That is to say you cannot do systems programming in Java.
I guess it might work out if there is a straight Java to native compiler. Is there such a beast?
Initially there were no native compilers, and frankly Sun was never keen on the idea. But several direct to machine language compilers have been created, including one by the GNU project http://gcc.gnu.org/java/
Things like unsigned ints might help. And get rid of the need for all functions to be methods of a class and...and....and oh looks like C again!
these projects had to be scrapped and rewrote in cpp using lots of small structered classes using new and delete and they are a dream to work with even being away from them for a few years i can go back and easily start modifiying the code.
here is one example is a small peice of mem release code in cpp from one of my projects.
now that small peice of code free's a few classes and thousands and thousands of allocated objects from they classes. to do this with malloc dealloc its just a plain nightmare. thats sort of what i ment.
I spent a lot of time programming in C and only a bit of time with C++ and OO programming. The time I spent with C was a long time ago however and I've forgotten more about both C and C++ than I remember.
I think it's important to remember that C was originally developed to be used for embedded programming and is by design a very low level language. I'd like to think that C++ was also designed for embedded work but it's hard to tell for sure since the libraries are so closely tied to the language and all the books I've seen on C++ are geared towards application type programming. One thing I do remember about C++ is that it hides a lot of the "ick" of C.
For what it's worth if it's worth anything I've been looking into "relearning C/C++ for the propeller and have decided on C++. The object oriented nature of C++ seems to be well suited for use on the propeller and I like the idea of being able to use constructors and destructors to start and stop cogs.
The reason for the tight coupling of C and C++ is that C++ is a superset of C and ansi compliant C code is valid and legal C++ code. Like spin C++ is an object oriented language. How many of the advanced "features" of C++ you use is entirely up to you and if you decide to learn C first do so with the knowledge that you're also learning C++ without the classes!
In my never humble opinion the reason why Java became popular for web sites is that it's platform agnostic. The same code can run on a client running windows, mac-os, linux, etc! Had nothing to do with it's "quality" as a language.
I always thought of C++ as a natural progression to C. To me, C is procedural and method based. While C++ has more of a data perspective. That is, if the programmer wishes.
Java is a tokenized language and as pointed out, it tends to be used on top of an OS.
I am aware that the OOP and garabage collection and so on are worthwhile features. But one must crawl before they walk and walk before they run. At times, it seems that it is getting harder and harder to find a good path for learning through all the programing languages that have come and gone.
Taiwanese are very much hanging on to Visual Basic - not because it is the best solution, but because it appeals to their comfort zone. Americans and Europeans have a richer history of computer languages to ponder and exploit. This all has to do with different degress of access across language barriers.
But there is a rather large corpus of examples of code in C. So if one doesn't understand C, one often just cannot read about programming with any real depth of comprehension. Even 'pseudo-code' is very much like C.
IMO, garbage collection is nice and a marketing ploy. Garbage collection is useful but does not stop memory leaks. Crappy code is not language specific.
On the other hand, OOP is a good thing to start learning now. The concepts are relatively easy to understand but it takes a lot of practice to implement effectively.