C++ C++;设置结构地址

C++ C++;设置结构地址,c++,memory,C++,Memory,通过下面的代码,我试图让hwPort中的结构从内存地址0x48001000开始。我现在被卡住了,我该怎么做 struct PortGPIOs { volatile uint32_t MODER; /*!< GPIO port mode register, Address offset: 0x00 */ volatile uint32_t OTYPER; /*!&l

通过下面的代码,我试图让hwPort中的结构从内存地址0x48001000开始。我现在被卡住了,我该怎么做

    struct PortGPIOs
    {
            volatile uint32_t MODER;        /*!< GPIO port mode register,               Address offset: 0x00      */
            volatile uint32_t OTYPER;       /*!< GPIO port output type register,        Address offset: 0x04      */
            volatile uint32_t OSPEEDR;      /*!< GPIO port output speed register,       Address offset: 0x08      */
            volatile uint32_t PUPDR;        /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C      */
            volatile uint32_t IDR;          /*!< GPIO port input data register,         Address offset: 0x10      */
            volatile uint32_t ODR;          /*!< GPIO port output data register,        Address offset: 0x14      */
            volatile uint16_t BSRRL;        /*!< GPIO port bit set/reset low register,  Address offset: 0x18      */
            volatile uint16_t BSRRH;        /*!< GPIO port bit set/reset high register, Address offset: 0x1A      */
            volatile uint32_t LCKR;         /*!< GPIO port configuration lock register, Address offset: 0x1C      */
            volatile uint32_t AFR[2];       /*!< GPIO alternate function registers,     Address offset: 0x20-0x24 */
            volatile uint32_t BRR;          /*!< GPIO bit reset register,               Address offset: 0x28 */
    };

    class hwPort {
        public:
            hwPort(PortGPIOs *, uint32_t, uint32_t, uint32_t);
            uint32_t read();
            void readOr(uint32_t);
            void readAnd(uint32_t);
            void write(uint32_t);
            void writeOr(uint32_t);
            void writeAnd(uint32_t);
        private:
            PortGPIOs *GPIO;
    };
struct PortGPIOs
{
易失性uint32_t MODER;/*!
只需在构造函数中初始化
GPIO
成员变量,如下所示:

        GPIO = (PortGPIOs *) 0x48001000;

[注意:如果愿意,请使用C++样式的强制转换-最终结果相同。]

重新解释强制转换
?这似乎是一句你想跳出来的话。这只是一个品味的问题——对于像这样的简单类型的转换,我通常更喜欢更简洁的C风格的转换,但是如果你喜欢的话,可以随意使用C++风格的转换。