首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >函数中引用未编译的

函数中引用未编译的
EN

Stack Overflow用户
提问于 2019-04-21 20:35:17
回答 1查看 38关注 0票数 1

我有这个简单的C代码,但是在写和读函数中包含了引用变量输入参数,使得程序无法编译。如果我删除&,程序是好的。我正在2017上运行这个程序。

代码语言:javascript
复制
#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];

有人能帮忙吗?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-21 20:41:05

这(volatile Modulation_format_cnfg& r)至少是其中一个问题。在c中,您必须按地址传递(而不是像在c++中那样直接通过引用传递)。为此,可能将该行更改为volatile Modulation_format_cnfg* r,将其传递给指针( &someStackVarmalloced堆内存),然后在函数中使用箭头操作符。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55786529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档