I have a simple sketch as shown below:
class Simple {
public:
byte* Data;
};
Simple simple;
byte data[3] { 0x41, 0x42, 0x43 };
void setup() {
simple.Data = data;
Serial.begin(9600);
}
void loop() {
Serial.print("sizeof(data): ");
Serial.println(sizeof(data));
Serial.print("sizeof(simple.Data): ");
Serial.println(sizeof(simple.Data));
for(int i = 0; i < sizeof(data); i++)
{
Serial.print(data[i]); Serial.print(' ');
}
Serial.println();
for(int i = 0; i < sizeof(simple.Data); i++)
{
Serial.print(simple.Data[i]); Serial.print(' ');
}
Serial.println();
for(int i = 0; i < sizeof(data); i++)
{
Serial.print(simple.Data[i]); Serial.print(' ');
}
Serial.println();
delay(1000);
}
Here is the output:
sizeof(data): 3
sizeof(simple.Data): 2
65 66 67
65 66
65 66 67
When I check the size of the array (sizeof(data)) and compare it to the size of the Data member of the class instance (sizeof(simple.Data)), they don't match. When I dump the contents of both arrays, they each have three elements.
I'm new to C/C++ (coming from a C# background) so my grasp of pointers et al is weak. Am I missing something here?
Thanx