gpt4 book ai didi

c - 如何将位域及其内部的位传递给函数

转载 作者:行者123 更新时间:2023-11-30 19:45:16 25 4
gpt4 key购买 nike

对于微 Controller ,您通常有一个寄存器及其位字段版本,使您能够单独访问每个引脚

假设我有来自两个位域的两个对象

struct {
unsigned a_A:1;
unsigned b_A:1;
unsigned c_A:1;
unsigned d_A:1;
unsigned e_A:1;
unsigned f_A:1;
unsigned g_A:1;
unsigned h_A:1;
}A;
struct {
unsigned a_B:1;
unsigned b_B:1;
unsigned c_B:1;
unsigned d_B:1;
unsigned e_B:1;
unsigned f_B:1;
unsigned g_B:1;
unsigned h_B:1;
}B;

如何构建一个接受位域及其位作为参数的函数就像

void my_func(bitfield,bit_name)

bit_name 应根据位域的每种类型而变化

最佳答案

怎么样

void my_func(unsigned a_B);
...
void my_func(unsigned h_B);

并调用它:

my_func(B.a_B);
...
my_func(B.h_B);

关于c - 如何将位域及其内部的位传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26697591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com