here's a memory dump of the contents of struct struct_message, renamed Msg
both 'a', the c-string and 'e', the String have the same values, "Some String". you can see the matching ASCII values 'a' contains, but 'e' contains just 6 values which aren't printable ASCII values
dump: msg
53 6f 6d 65 20 53 74 72
69 6e 67 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ad 7e 00 00 80 3f d4 02
0b 00 0b 00 01
dump: msg.a - char[]
53 6f 6d 65 20 53 74 72
69 6e 67 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
dump: msg.b - int
ad 7e
dump: msg.c - float
00 00 80 3f
dump: msg.d - String
d4 02 0b 00 0b 00
dump: msg.e - bool
01
1 sizoef char
2 sizoef int
4 sizoef float
6 sizoef String
1 sizoef bool
struct Msg {
char a[32];
int b;
float c;
String d;
bool e;
};
Msg msg = { "Some String", 0x7ead, 1.0, "Some String", 1 };
char s [90];
// -----------------------------------------------------------------------------
void
dump (
uint8_t *p,
unsigned nByte,
const char *label )
{
sprintf (s, "dump: %s", label);
Serial.print (s);
for (unsigned n = 0; n < nByte; n++) {
if (! (n % 8))
Serial.println ();
sprintf (s, " %02x", *p++);
Serial.print (s);
}
Serial.println ();
Serial.println ();
}
// -----------------------------------------------------------------------------
void
dumpMsg (
Msg msg )
{
dump ((uint8_t*) & msg, sizeof(msg), "msg");
dump ((uint8_t*) & msg.a, 32, "msg.a - char[]");
dump ((uint8_t*) & msg.b, sizeof(int), "msg.b - int");
dump ((uint8_t*) & msg.c, sizeof(float), "msg.c - float");
dump ((uint8_t*) & msg.d, sizeof(String), "msg.d - String");
dump ((uint8_t*) & msg.e, sizeof(bool), "msg.e - bool");
}
// -----------------------------------------------------------------------------
void
setup (void)
{
Serial.begin (9600);
dumpMsg (msg);
sprintf (s, " %2d sizoef %s", sizeof(char), "char"); Serial.println (s);
sprintf (s, " %2d sizoef %s", sizeof(int), "int"); Serial.println (s);
sprintf (s, " %2d sizoef %s", sizeof(float), "float"); Serial.println (s);
sprintf (s, " %2d sizoef %s", sizeof(String), "String");Serial.println (s);
sprintf (s, " %2d sizoef %s", sizeof(bool), "bool"); Serial.println (s);
}
void
loop (void)
{
}