cmnrd / yalla

Yet Another Lovely Lib for AVR
MIT License
12 stars 1 forks source link

Using reinterpret_cast in constexpr expression #19

Open lamer0k opened 5 years ago

lamer0k commented 5 years ago

Hello Christian , greate work.! I have a question about the contexpr. In the file iomm.hpp, line 53, the next code:

using PtrType = volatile T*;
static constexpr PtrType ptr = reinterpret_cast<PtrType>(_addr);

C++ reject to use reinterpret_cast in constexpr expression. Does it realy work on gcc compiler? It coul be a cause that all objects will be placed in RAM, and all functions also will not be run on compile time.

cmnrd commented 5 years ago

Thanks for the feedback lamer0k! Since I don't use AVRs this often anymore, I didn't work on this project for some years now. Back then this code used to work. I didn't find a clear statement, but it might be that this only became illegal in C++14 and was not illegal in C++11 (only unspecified). Back then I was new to C++11 and not aware that this is unspecified behaviour.

I found this https://arne-mertz.de/2017/06/stepping-away-from-define/ in a quick search. To me, this looks like a good alternative for handling the pointers in yalla.

I currently don't have the time to fix this myself, but I would be happy to accept a pull request.