小编Pat*_*Pat的帖子

Makefile ifeq逻辑或

如何使用make的ifeq运算符执行逻辑OR ?

例如,我有(简化):

ifeq ($(GCC_MINOR), 4)
    CFLAGS += -fno-strict-overflow
endif
ifeq ($(GCC_MINOR), 5)
    CFLAGS += -fno-strict-overflow
endif
Run Code Online (Sandbox Code Playgroud)

但想巩固这些界限.

(是的,是的,autotools,配置等等;对于当前的情况太过苛刻,想在这里保留Makefile中的所有内容)

[与此问题逻辑相反:如何在'ifeq'语句中使用多个条件 ]

makefile

83
推荐指数
4
解决办法
12万
查看次数

c标准和位移

这个问题首先受到此代码的(意外)结果的启发:

uint16_t   t16 = 0;
uint8_t     t8 = 0x80;
uint8_t t8_res;

t16    = (t8 << 1);
t8_res = (t8 << 1);

printf("t16: %x\n", t16);    // Expect 0, get 0x100
printf(" t8: %x\n", t8_res); // Expect 0, get 0
Run Code Online (Sandbox Code Playgroud)

但事实证明这是有道理的:

6.5.7按位移位运算符

约束

2每个操作数应具有整数类型

因此,最初混淆的线相当于:

t16 = (uint16_t) (((int) t8) << 1);
Run Code Online (Sandbox Code Playgroud)

有点不直观的恕我直言,但至少定义明确.

好的,很棒,但接下来我们做了:

{
uint64_t t64 = 1;
t64 <<= 31;
printf("t64: %lx\n", t64); // Expect 0x80000000, get 0x80000000
t64 <<= 31;
printf("t64: %lx\n", t64); // Expect 0x0, get 0x4000000000000000 …
Run Code Online (Sandbox Code Playgroud)

c standards bit-shift

5
推荐指数
2
解决办法
2600
查看次数

具有非连续布局的C位域元素

我正在寻找最优雅的接口上的输入来放置内存映射的寄存器接口,其中目标对象在寄存器中被分割:

union __attribute__ ((__packed__)) epsr_t {
    uint32_t storage;
    struct {
        unsigned reserved0    : 10;
        unsigned ICI_IT_2to7  :  6; // TOP HALF
        unsigned reserved1    :  8;
        unsigned T            :  1;
        unsigned ICI_IT_0to1  :  2; // BOTTOM HALF
        unsigned reserved2    :  5;
    } bits;
};
Run Code Online (Sandbox Code Playgroud)

在这种情况下,访问单个位T或任何reserved字段工作正常,但要读取或写入ICI_IT需求代码更像:

union epsr_t epsr;
// Reading:
uint8_t ici_it = (epsr.bits.ICI_IT_2to7 << 2) | epsr.bits.ICI_IT_0to1;
// Writing:
epsr.bits.ICI_IT_2to7 = ici_it >> 2;
epsr.bits.ICI_IT_0to1 = ici_it & 0x3;
Run Code Online (Sandbox Code Playgroud)

在这一点上,我已经失去了bitfield抽象试图提供的简单/便利的一大块.我考虑过宏观解决方案:

#define GET_ICI_IT(_e)      ((_e.bits.ICI_IT_2to7 << …
Run Code Online (Sandbox Code Playgroud)

c embedded struct unions bit-fields

5
推荐指数
2
解决办法
466
查看次数

使用假冒的Makefile通配符(静态规则?)

我刚刚开始真正了解make的内部工作原理.但我不明白为什么以下不起作用:

test%: test%.foo
     @echo $@
     @echo $<

all: test1 test2

.PHONY: all test1 test2
Run Code Online (Sandbox Code Playgroud)

预期行为:

$ make
test1
test1.foo
test2
test2.foo
# 1,2 Order not important
Run Code Online (Sandbox Code Playgroud)

但是,我得到:

$ make
make: Nothing to be done for `all'.
Run Code Online (Sandbox Code Playgroud)

("make all","make test1"等没有区别).

有人可以解释为什么PHONY测试规则没有被执行?

makefile target

4
推荐指数
1
解决办法
2753
查看次数

标签 统计

c ×2

makefile ×2

bit-fields ×1

bit-shift ×1

embedded ×1

standards ×1

struct ×1

target ×1

unions ×1