我有这个简单的C代码,但是在写和读函数中包含了引用变量输入参数,使得程序无法编译。如果我删除&,程序是好的。我正在2017上运行这个程序。
#include <stdio.h>
#include <stdint.h>
typedef struct Cr Cr;
typedef struct Modulation_format_cnfg Modulation_format_cnfg;
struct Modulation_format_cnfg {
union {
struct
{
uint32_t sc0 : 3;
uint32_t : 5;
uint32_t sc1 : 3;
uint32_t : 5;
uint32_t sc2 : 3;
uint32_t : 5;
uint32_t sc3 : 3;
uint32_t : 5;
};
uint32_t raw;
};
};
struct Cr
{
uint32_t const kBlock_base_addr;
Modulation_format_cnfg volatile modulation_format_cnfg;
};
void write(volatile Modulation_format_cnfg& r, const int val) {
r.raw = val;
}
uint32_t read(Modulation_format_cnfg volatile& r, const int val) {
return r.raw;
}
Cr cr[2];有人能帮忙吗?
提前感谢!
发布于 2019-04-21 20:41:05
这(volatile Modulation_format_cnfg& r)至少是其中一个问题。在c中,您必须按地址传递(而不是像在c++中那样直接通过引用传递)。为此,可能将该行更改为volatile Modulation_format_cnfg* r,将其传递给指针( &someStackVar或malloced堆内存),然后在函数中使用箭头操作符。
https://stackoverflow.com/questions/55786529
复制相似问题