So i know that the native arduino language is written in c/c++, but does that mean that i can write pure c code in the arduino ide, or that i have to use the arduino specified language? I’m new to this and very confused, please bear with me here :’)
asked Mar 15, 2022 at 18:13 21 2 2 bronze badgesThere is no Arduino specific language. Its just C++. Arduino just gives you a framework inside C++ to work with, like a predefined program structure (loop and setup function) and useful functions and libraries. But sure, you can use C code for Arduino - up to the point where the two languages are diverging from one another. It is not easy to spot the exact border on what of the new C features are supported, though with all older C code you should be good. Does this help? If not, can you explain more what confuses you?
Commented Mar 15, 2022 at 18:27Yes, you can write in pure C. Some parts of the Arduino core API are actually defined in C, e.g. pinMode() and digitalWrite() (at least in the AVR core). So you can use them. Other parts, like Serial , are C++ objects, and you will not be able to use them from plain C.
The Arduino IDE, however, will insist on you writing a file with the .ino extension, that it will compile as preprocessed C++. You do not need to put anything in that file though. If you want to write your whole program in pure C, you can create an empty .ino file, and in the same folder a .c file with your whole program. In that file you can define your own main() . If you want to use the Arduino core API though, you should instead define setup() and loop() , and rely on the core-provided main() .
answered Mar 15, 2022 at 19:15 Edgar Bonet Edgar Bonet 43.9k 4 4 gold badges 40 40 silver badges 78 78 bronze badgesTo subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2024.9.11.15092