Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
test C++ register
//clang 3.8.0 #include <iostream> #include <array> typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef unsigned int uINT; namespace registers { template<u32 pon_def, bool single_bf> struct register_t { constexpr static u32 const PON_DEF = pon_def; constexpr static u32 const SINGLE_BF = single_bf; }; } template<u32 bitoffset, u32 bitlength, u32 mask, bool maskable, u32 pon_def, bool byte_writeable> struct registerfield_attr_t { constexpr static u32 const BITOFFSET = bitoffset; constexpr static u32 const BITLENGTH = bitlength; constexpr static u32 const MASK = mask; constexpr static bool const MASKABLE = maskable; constexpr static u32 const PON_DEF = pon_def; constexpr static bool const BYTE_WRITEABLE = byte_writeable; }; //! @brief bitfield structure of register RSU_EIRQ_S_REG (0x60000C0C). struct rsu_eirq_s_reg_t final : registers::register_t<0x00000000, true> { union { struct { uINT RSU_EIRQ_S_BUS_TIMEOUT : 4; // rws, pon_def = 0 uINT : 28; // reserved }; u32 value; }; //Bitfield attributes (BITOFFSET, BITLENGTH, MASK, MASKABLE, PON_DEF, BYTE_WRITEABLE) constexpr static registerfield_attr_t<0U, 1U, 0x00000001U, 0, false, true> const RSU_EIRQ_S_BUS_TIMEOUT_ATTR = {}; }; u32 value; volatile rsu_eirq_s_reg_t & RSU_EIRQ_S_REG = *reinterpret_cast<rsu_eirq_s_reg_t volatile *>(&value); int main() { std::cout << "Hello, world!\n"; std::cout << sizeof(rsu_eirq_s_reg_t) << std::endl; std::cout << rsu_eirq_s_reg_t::PON_DEF << std::endl; std::cout << rsu_eirq_s_reg_t::SINGLE_BF << std::endl; rsu_eirq_s_reg_t foo; foo.RSU_EIRQ_S_BUS_TIMEOUT = 1; RSU_EIRQ_S_REG.value = 5; std::cout << RSU_EIRQ_S_REG.RSU_EIRQ_S_BUS_TIMEOUT << std::endl; }
run
|
edit
|
history
|
help
0
C++ Standard Template Library
virtual members
MPL 2-0
mddd
C++17 function traits not works
constructor-is-not-called-in-this-aggregation-class
lref assignment
Division by zero exception example
khcmknhc
return reference (clang)