I'm new to arduino, but I'm an old hand at C and C++. Can somebody tell me if arduino structs are like new C (ie C++) where typedef isn't really needed as you can declare a struct object type by just using "struct foo {}; " and then later declare instances with just "foo fooInstance;"? Or must I mimic this by using typedef as a workaround, per old C?
Any chance there's "class" or "enum"?
Do I have to use pointers to pass structs around, or are they created equal with other variable types?
Curly brace struct initialization?
I tried to find some discussion of structs in the language reference. Oddly is wasn't there (the reference barely explains arrays). Maybe I was looking at the wrong language reference.
Lots of garbage websites that purport to explain arduino structs are at a sub-beginner level. I hope somebody can point me to the real stuff.
The struct is not a directive; it is a keyword of C Language. It is the class keyword that was introduced in C++ by Bjarne Stroustrup (pronounced as) in 1983.
1. I am telling based on K&R's Legendary "The C Programming Language" Book:
(1) The struct is a keyword. It introduces/encaptulates a data structure of conglomerate type as declared below and enclosed within pair of braces:
struct
{
int x;
int y;
float z;
} ;
(2) An optinal name called structure tag (simply tag) may follow the keyword struct. Given below an example; where, point is a tag. The tag can be used subsequently as a shorthand to refer the declaration in braces of Step-1(1).
struct point
{
int x;
int y;
float
} ;
==>
struct point pt;
In the above, pt is a variable which is a structure of type "struct point". It is an instance of the structure.
The variable pt has never been uttered as an object in this Book of C, ; it is a concept introduced in C++ that encpsulates both "data and methods".
(3) In K&D's Book, I have not seen the structure declaration to contain the following access specifiers which are seen in "C++ Class Declaration".
private:
public:
protected:
(4) In C++, the tag is enough to refer the structure declaration; there is no need for the tage to follow the class keyword. In C, the tag follows the struct keyword as is seen in Step-1(2). For example:
class Rectangle
{
private:
int width;
int length;
public:
Rectangle(int, int);
void calArea();
};
Rectangle rect(4, 5); //object has followed the Class Name = Calss Tag
You can not compare what K&R wrote in e.g. their second edition book with a modern C++.
The difference between a modern C++ struct and a class is that all members of a struct are public by default and all members are private by default. And that is how far my knowledge goes.
OK, thanks for all the helpful replies. What I'm gathering from the response is that the "arduino language" is C++. Is this correct to say? Or is it some C++ subset? For example, can I do operator overloading in arduino? It's weird that there's no reference. What's the compiler -- is it just gnu g++ or some such? If so, then all my questions are thereby answered. Or is it something specifically created for arduino. I know that CS people love to make new compilers for things. Was that done here, or is it just the gnu compiler with a glitzy IDE?
What are the advantags of using Arduino IDE Platform to develop applications for ATmega328P Microcontroller?
1. I am an Assembly Language Programmer. (I assume that) Arduino IDE Platform is not known to me. I am familiar with Microchip Studio. I can develop any application whatever I like and of course up to the level of my expertise.
2. Arduino IDE offers the following facilities: (1) Complex data structures of the target MCU can be handled (at almost Natural Language level) using C++ Programming Language.
(2) Sensors Interfacing have been made easy by the manufacturers/third parties through the supply of Library Files/Functions which are compatible with C++ Language of the Arduino IDE.
(3) Devices Interfacing (WiFi, Graphics Display, etc.) have been made easy by the similar scheme of Step-2(2).
(4) An excellent platform for learning the syntax and semantics rules of C++ Language being able to see the outcomes of experiments and imaginations at hardware levels.