This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:introductiontoembeddedprogramming2:cppfundamentals:structuresandclasses [2023/11/21 19:43] – ktokarz | en:iot-open:introductiontoembeddedprogramming2:cppfundamentals:structuresandclasses [2023/11/23 10:21] (current) – pczekalski | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Structures and Classes ====== | ====== Structures and Classes ====== | ||
+ | {{: | ||
Structures and classes present complex data types, definable by the developer. Not all C/C++ programming environments provide support for classes (e.g., STM32 in HAL framework mode does not), but luckily, the Arduino framework supports it. Structures, conversely, are part of the C language definition and are present in almost every implementation of software frameworks for IoT microcontrollers. | Structures and classes present complex data types, definable by the developer. Not all C/C++ programming environments provide support for classes (e.g., STM32 in HAL framework mode does not), but luckily, the Arduino framework supports it. Structures, conversely, are part of the C language definition and are present in almost every implementation of software frameworks for IoT microcontrollers. | ||
- | === Structures === | + | ==== Structures |
In C and C++, a structure is a user-defined data type that allows you to combine different types of variables under a single name. | In C and C++, a structure is a user-defined data type that allows you to combine different types of variables under a single name. | ||
Line 74: | Line 75: | ||
</ | </ | ||
- | === Classes === | + | ==== Classes |
Classes were introduced in C++ to extend structures encapsulating data and methods (functions) to process this data. A method presented above in the structure context brings an overhead with a need to pass a pointer to the structure for each call. Moreover, it makes access levels tricky, e.g. when you do not want to expose some functions but use them for internal data processing. Thus, classes can be considered as an extension of the structures.\\ | Classes were introduced in C++ to extend structures encapsulating data and methods (functions) to process this data. A method presented above in the structure context brings an overhead with a need to pass a pointer to the structure for each call. Moreover, it makes access levels tricky, e.g. when you do not want to expose some functions but use them for internal data processing. Thus, classes can be considered as an extension of the structures.\\ | ||
< | < |