T
trthientuong
Guest
I like tni's program too, that's so amazing to learning c++.
constexpr SPIClass(uintptr_t myport, uintptr_t myhardware)
: port_addr(myport), hardware_addr(myhardware) {
}
uintptr_t port_addr;
KINETISK_SPI_t & port() { return *(KINETISK_SPI_t *)port_addr; }
port().PUSHR = *p_write++ | SPI_PUSHR_CONT | SPI_PUSHR_CTAS(0);
Edit: It appears to be required if our constructor is defined as consstexpr
Correct. It's the equivalent of these Wire changes:Now I am wondering about something in new SPI code that probably is obvious to others, but wondering.
That is for the constructor, instead of simply passing in a pointer or reference to some other objects/structures, it instead passes in these values as:
uintptr_t values, and then has helper function to cast the value to a reference to that structure.
...
Edit: It appears to be required if our constructor is defined as consstexpr
In-class definitions are automatically inline. 'port()' does get inlined.Also wonder if helper function port() should be marked inline?
Having a constexpr constructor fixes initialization order issues. E.g., if someone has a global instance of some object that uses Wire or SPI in the constructor, they might not be initialized when they are used (if they don't have the constexpr constructor):I'm wondering if this type of declaration and usage is to avoid security holes?