Go Down

Topic: Programming in C (Read 5 times) previous topic - next topic

dhenry

Quote
When you say C: structure, are you referring to the structure of a typical C: drive on a PC?


It is about your ability to break down a complex task into well defined pieces so that when they are re-assembled, they work flawlessly together. That's where the money is, besides creativity.

tuxduino


Quote
When you say C: structure, are you referring to the structure of a typical C: drive on a PC?


It is about your ability to break down a complex task into well defined pieces so that when they are re-assembled, they work flawlessly together. That's where the money is, besides creativity.


Hmmm.... that requires creativity, too (often).  :)

jtw11

Quote
It is about your ability to break down a complex task into well defined pieces so that when they are re-assembled, they work flawlessly together. That's where the money is, besides creativity.


That's exactly what I'm doing now - just documenting program flow charts, that define exactly what must happen, and when - saving on RAM using is high on the priority list with this project, and thus all terms are controlled as to when they refresh or are recalculated.

pico


There's no such thing as the "Arduino language."  Arduino is programmed in C++.


From the arduino.cc home page:

Quote

The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing).


Now, we all know that description by "Team Arduino" is a bit of stretch -- the "Arduno Language", if it exists, is a certain amount of IDE preprocessing of the .pde/.ino "sketch" files that convert certain non-C++ Arduino specific stuff into "real" C++ that the g++ compiler can actually compile.

But it should be made clear that when you program in the Arduino IDE, there are enough differences that mean the syntax and semantics depart from standard C++ (in particular, the the C/C++ preprocessor), and these can lead to unexpected (and sometimes inconsistent) results that can be confusing to anyone who has actually programmed in C/C++ before.

Perhaps calling the "Arduino Language" an attempt at a simplified "dialect" of C/C++ is a fairer description?

I just think of the differences as simply "broken", mostly. But the "team" will say that substituting the standard keyword "bool" with "boolean", and saving the user from having to declare their own function prototypes, and hiding compiler warnings and error messages from users so as to not upset them, are helpful to novice programmers. So all a matter of taste, I suppose. I myself actually program Arduinos without using the IDE, so I can stay in standard C++, and avoid all the non-standard Arduinoisms.

As to the question of learning C or C++ first, I'd recommend learning C first. It's a smaller, simpler and cleaner language, and in many ways more coherent than C++, which is (relatively) vast, complex and untidy. Once you've mastered C, it's a matter of learning C++ incrementally as a series of extensions the basic core of the C language. Almost all of C is necessary to program effectively, much of C++ is not.

In my opinion, the first and last book you'll need for learning C is "The C Programming Language" by Kernighan and Ritchie. Like the C language itself, the text is small, simple and clean. A classic. :)

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

tuxduino

Just a note:

Quote
there are enough differences that mean the syntax and semantics depart from standard C++


definitely not, IMHO. A "non-stadard" syntax sketch would certainly _not_ compile. As for the semantics, the Reference section documents the included libraries, while for everything else one can search "normal" (i.e. non-Arduino specific) online c++ documentation.

AWOL

Well, C and C++ require either pre-declaration of functions or function prototypes, so any forward references would fail in a straightforward C/C++ environment.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

fungus


But it should be made clear that when you program in the Arduino IDE, there are enough differences that mean the syntax and semantics depart from standard C++


What the Arduino web site refers to as "Arduino Language" is really the Arduino library: http://arduino.cc/en/Reference/HomePage

The programming language used is C++, I don't think there's any difference in syntax or semantics apart from "PROGMEM".

The IDE inserts the Arduino header files and generates function prototypes for you (so you don't have to worry about forward references), that doesn't really change anything about the programming language.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

pico

#37
Nov 23, 2012, 04:17 pm Last Edit: Nov 23, 2012, 04:27 pm by pico Reason: 1

The programming language used is C++, I don't think there's any difference in syntax or semantics apart from "PROGMEM".


As I mentioned, there are both syntactic and semantic differences, particularly with respect to C/C++ preprocessor (which is part of the C/C++ standard).

By semantic differences, I mean things that have the same syntax but different meaning or interpretation. For example, both "Arduino language" and C++ will compile this excerpt without a syntax error, but with very different results:

#define FOO 1

#if FOO
#include <mylib.h>
#else
#include <theirlib.h>
#endif

A trivial syntactic difference between "Arduino Language" and C++ is the replacement of "bool" with "boolean". (And what were they thinking, anyway?)

A less trivial (and more important) syntactic difference is

#include "file_with_arbitrary_extens.ion"

will preprocess and compile happily in C++, but not in "Arduino Language" as defined by the IDE preprocessor.

Finally, if "Team Arduino" want to call their implementation of the wiring lib a "programming language", more power to them. It's not what anyone I know would call a programming language, however.

But at the end of the day, whatever it is, "Arduino Language" != C++. As I said above, an attempt at a "simplified dialect" would be the most generous description I can think of.
WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

AWOL

Code: [Select]
#include >theirlib.h>

Getting that to compile would be a feat and a half in any system.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

pico

#39
Nov 23, 2012, 04:30 pm Last Edit: Nov 23, 2012, 04:32 pm by pico Reason: 1

Code: [Select]
#include >theirlib.h>

Getting that to compile would be a feat and a half in any system.


You replied before I spotted it and could edit it! You are fast off the mark. :)

Actually, that example would compile, because the  #include >theirlib.h> line would be preprocessed out by the standard C/C++ preprocessor. I'm not sure what the IDE preprocessor would do with it, however. Which further demonstrates the point, I suppose.
WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

retrolefty

#40
Nov 23, 2012, 04:31 pm Last Edit: Nov 23, 2012, 04:34 pm by retrolefty Reason: 1
Nice nerd arguments so far. I'm a hardware guy so my opinions are of questionable value in a topic like this. But I base my opinion (that arduino's are programmed in the C++ language) simply based on the fact that the IDE calls the gcc compiler to compile the sketch. The fact that there are things being done by the arduino preprocessor, while interesting and good to know and understand, doesn't change my opinion that the arduino does not use a programming language other then C++. It's not like the preprocessor is acting like a front end language converter that might say convert Fortran or Basic statements to C/C++ statements.

But I enjoy reading nerd arguments anyway, they are much better then political arguments. Keep them coming.  ;)

Lefty

pico

#41
Nov 23, 2012, 04:37 pm Last Edit: Nov 23, 2012, 04:39 pm by pico Reason: 1

But I base my opinion (that arduino's are programmed in the C++ language) simply based on the fact that the IDE calls the gcc compiler to compile the sketch. The fact that there are things being done by the arduino preprocessor, while interesting and good to know and understand, doesn't change my opinion that the arduino does not use a programming language other then C++.


Then you might as well say that the Arduino Language is actually assembly language, since the g++ compiler in turn translates the C/C++ syntax into assembly (it actually generates a .S file during compilation, and the gnu assembler turns it into machine code).


It's not like the preprocessor is acting like a front end language converter that might say convert Fortran or Basic statements to C/C++ statements.


This is pretty close to the mark, actually.
WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

dhenry

Quote
In my opinion, the first and last book you'll need for learning C is "The C Programming Language" by Kernighan and Ritchie. Like the C language itself, the text is small, simple and clean. A classic.


2nd that. I would add, however, that K&R is probably beyond the comprehension of most C programmers and 99.99% of the arduino community. Without years or programming, making mistakes and tracking down those nasty bugs, it is not possible to appreciate it fully.

Quote
what were they thinking, anyway?


I would add to that list the (ab)use of int.

Quote
As I said above, an attempt at a "simplified dialect" would be the most generous description I can think of.


It may be more complicated than that. Arduino is meant to be used by people who are new to mcu, and likely will not utilize the environment for complex tasks. As such, a simplified dialect (dumbed down version of a fully C-compliant implementation) likely is more productive for its intended audience / niche.

retrolefty

As I said keep them coming. My role in life here is just to be sure arduino beginners understand to use resistors with their leds and separate power source for their servos.  ;)

Lefty

fungus


A trivial syntactic difference between "Arduino Language" and C++ is the replacement of "bool" with "boolean". (And what were they thinking, anyway?)


"bool" works... I use it all the time.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Go Up