brtaylor
Well-known member
I'm trying to compile for Teensy3.x with a makefile using a newer C++ compiler and the Wire library. I'm running into the error 'reinterpret_cast from integer to pointer' (previously it would have just been a warning). Specifically, it's complaining about SIM_SCGC4 on this line:
https://github.com/PaulStoffregen/W...3d5971b6fe4828d08c857df9/WireKinetis.cpp#L839
SIM_SCGC4 is defined in kinetis.h:
https://github.com/PaulStoffregen/c...c84e62b5c0e9243128416/teensy3/kinetis.h#L1193
My understanding is that reinterpret_cast is not allowed in constexpr since it may result in undefined behavior (in general, not in this case). I'm not sure what the "right" fix is in this case to make the compiler happy and avoid other potential issues. I suppose the easiest would be to remove constexpr in TwoWire::I2C_Hardware_t TwoWire::i2c0_hardware, but between this and the MAKE_CONST macro (https://github.com/PaulStoffregen/W...3d5971b6fe4828d08c857df9/WireKinetis.cpp#L907), it seems like a lot of work went into making everything evaluate at compile time, and I'd hate to lose that efficiency. Any thoughts?
Thanks!
Brian
Code:
constexpr TwoWire::I2C_Hardware_t TwoWire::i2c0_hardware = {
SIM_SCGC4, SIM_SCGC4_I2C0,
#if defined(__MKL26Z64__) || defined(__MK20DX128__) || defined(__MK20DX256__)
18, 17, 255, 255, 255,
2, 2, 0, 0, 0,
19, 16, 255, 255, 255,
2, 2, 0, 0, 0,
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
18, 17, 34, 8, 48,
2, 2, 5, 7, 2,
19, 16, 33, 7, 47,
2, 2, 5, 7, 2,
#endif
IRQ_I2C0
};
SIM_SCGC4 is defined in kinetis.h:
Code:
#define SIM_SCGC4 (*(volatile uint32_t *)0x40048034) // System Clock Gating Control Register 4
My understanding is that reinterpret_cast is not allowed in constexpr since it may result in undefined behavior (in general, not in this case). I'm not sure what the "right" fix is in this case to make the compiler happy and avoid other potential issues. I suppose the easiest would be to remove constexpr in TwoWire::I2C_Hardware_t TwoWire::i2c0_hardware, but between this and the MAKE_CONST macro (https://github.com/PaulStoffregen/W...3d5971b6fe4828d08c857df9/WireKinetis.cpp#L907), it seems like a lot of work went into making everything evaluate at compile time, and I'd hate to lose that efficiency. Any thoughts?
Thanks!
Brian