Pointer iteration Question

@cncnotes This is a helpful way to think about it. Thank you. Also, the array size is declared earlier in the code :slight_smile:

@cedarlakeinstruments

So, using the asterisk in the Serial.read() is telling it where to put the data, but when incrementing it, the asterisk isn't needed because we are only moving the pointer("cursor") location and not sending data to that location, correct? Thank you so so much again for your responses.

You are correct, but as a matter of principle I try to avoid any constructs that rely on remembering order of operation. It's too easy to make a mistake. I'd rather dereference the pointer and then do the increment as two separate statements.

2 Likes

Amen to that.

cool, cool. I'm slowly gaining insight. TYVM! I thought it would parse l to r ...

While I generally agree with this (or using parentheses to make the order explicit), there are certain constructs that are so ubiquitous that you may as well commit them to memory. The "deference + post-increment" operation (*ptr++) is one of them. You're highly likely to encounter it in most any code example you study … assuming it's written by somebody that know what they're doing.

Yeah, fetch and increment is REALLY useful.

What I really notice is the "mapping" of Cx functions overlay almost directly with the underlying CPU. ++ is INC, -- is DEC etc. If it was easy in ASM, it got early and simple opcodes. The PDP-11 data types got glued into the 8x86 model. Lots of more or less register indirect opcodes hiding just behind the C syntax.

It seems to me that you are confused. This is not "array is a pointer", but "array of pointers".

so, the declaration

char* messageSent [10] = {};

means "10 element's array of pointers to char"
Perhaps the difference seems insignificant to you - but then it leads you to an error:

Your calculations are incorrect because messageSent is not array of chars, but array of pointers to char. Pointer has size at least 2 bytes(depend on architecture). So the value of interest will be found at address 0xFF23+2* (sizeof (char*)), for example on arduino it will be 0xFF23+4

1 Like

Yes, you are quite right :grin: Brain lock. Thanks for correcting.
And indeed the difference is quite significant.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.