Go Down

Topic: syntax command Arduino IDE vs. C-language, same? (Read 2727 times) previous topic - next topic

uelman

>>> are the syntax commands (for C-programming) in Arduino IDE different from "pure" C-Language commands?
>>> if they have a slight difference, then I should focus on Arduino's frequently used commands, right?
>>> Is it just that the Compiler makes the difference, since either "other" Compiler or Arduino simply needs the HEX file to transfer the code to the  uC like Atmega ?

wildbill

The compiler that deploys with the IDE is gcc, so the Arduino is programmed in plain old C/C++. There are also some Arduino specific libraries with helpful functions like digitalWrite. Finally, the IDE transforms your code a little to add a main function and prototypes. In consequence, you can use any C++ constructs you desire.

graynomad

At the basic level the Arduino "language" is exactly the same as C/C++ because that's all it is.

There are however many library functions such as digitalWrite() that may appear to be part of the language but really are just functions written to make life easier. These will not directly port to another environment. The reverse is also true, functions you may be used to say on a PC using Visual C may not work on an Arduino, for example anything to do with the file system.

One other gotcha is as wildbill says, the IDE rearranges your code a bit to help beginners, for example you can easily declare a function after it's referenced and not have a prototype before the reference because the IDE sticks the prototype in for you. That practice will cause the code to fail the compile in other environments.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

GoForSmoke

#3
Nov 19, 2013, 05:16 am Last Edit: Nov 19, 2013, 05:22 am by GoForSmoke Reason: 1
What's under the Arduino easier-to-use IDE custom framework "hood":

http://www.nongnu.org/avr-libc/user-manual/index.html

http://www.nongnu.org/avr-libc/user-manual/modules.html

There is also an Arduino version of the free Code::Blocks IDE, but I haven't needed it yet. I have used Code::Blocks for PC code and it's got better debugging though I haven't found an auto-format like the Arduino IDE has.

http://sourceforge.net/projects/arduinodev/?source=dlp

edit:add

Please be aware that Arduino's like UNO, even MEGA have limited RAM. UNO has 2k for heap and stack and 32k flash ROM for program and constant data (usually tables and text). It is not a good idea to use dynamic objects in such small RAM space even if that's how you do it on a PC. Learn/Use string.h for text manipulation or just evaluate chars with your own routines and you will be able to pack much more into your code.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

pico

#4
Nov 19, 2013, 05:20 am Last Edit: Nov 19, 2013, 05:32 am by pico Reason: 1

One other gotcha is as wildbill says, the IDE rearranges your code a bit to help beginners, for example you can easily declare a function after it's referenced and not have a prototype before the reference because the IDE sticks the prototype in for you. That practice will cause the code to fail the compile in other environments.


The other "other" gotcha with the IDE is that it breaks compatibility with the standard C/C++ pre-processor in a number of important ways. So your #include directives won't work as expected, and a referring to a standard C/C++ pre-processor reference will be confusing.

So not exactly C++, at least according to the published standards, but close, for the main part.

FWIW, I disagree that the IDE rearranging your code in this way helps beginners, since a) it leads to confusion when referring to standard references on C/C++, and b) declaring prototypes is no big deal anyway (if you can write a function, you can cut and paste the prototype from the function declaration in about three keystrokes.)

But that's a debate for another time, I suspect.

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.)

pico


I haven't found an auto-format like the Arduino IDE has.


Just use the "external editor" option (in "preferences") with any syntax aware programmers' editor. I use emacs, which even has an "Arduino mode" (which is just a slightly tweaked C++ mode).

But just about any decent programmers' editor will be C/C++ syntax aware and able to do auto-format, brace checking, etc.
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.)

Go Up