Pointers and casting interpretation/reading logic

Hi,
I don't have access to the function definition of this:

I2C_Write(2, TCA9535_ADDRESS, TCA9535_CONFIG_REG0, (unsigned char*)&Regs->Config, 0);

And don't understand what the 4th parameter type is:
(unsigned char*)&Regs->Config

What is a general simple logic to understanding, reading and "decoding" any such referencing? i.e. pointers mixed with casting and dereferencing?

For example I came across the "left to right rule" (??) but still not clear how it works and where the starting point in that line of code is.

Thank you
Regs: Take the pointer named 'Regs', ...
->: ...dereference and access its member named...
Config: ...'Config',
&: take the address of that...
(unsigned char *): ...and pretend like that address points to an unsigned char, no matter what it actually points to.
Part of understanding it is just experience with the idea behind what it is doing (this helps unravel it and make sense of it. Even if you can read it, as explained above, its still gibberish if you don't know WHY it does what it does). So for that...

A *lot* of 'serial' tools just deal with blocks of raw bytes. Network transmissions, binary file writes, and similar things all want bytes, and deal with char* or unsigned char* as the method of moving the blocks of bytes around. I don't know what IC2 is but the word "write" tells me its going to be similar to these ideas; for example take a look at https://www.cplusplus.com/reference/ostream/basic_ostream/write/ and after reading that be sure to look at your documentation for IC2 write function.
Last edited on
Registered users can post here. Sign in or register to post.