小编Mik*_*vey的帖子

Haskell中的本地中缀运算符定义

在这个Haskell程序中,@@是一个中缀运算符,我只想在函数体内本地定义f.(当然,我的实际程序比这更复杂,并且有充分的理由使用中缀表示法.)

infixl 5 @@

(@@) = undefined

f x = x @@ 5 where x @@ y = (x+1) * (y+1)

main = print (f 7)
Run Code Online (Sandbox Code Playgroud)

然而,除非我也做出全球定义,在此写成(@@) = undefined,GHC抱怨"固定签名@@缺乏附带的约束力".如果没有运算符符号的全局定义,有没有办法绕过这个?

haskell

11
推荐指数
1
解决办法
459
查看次数

GCC 优化会损坏系统调用存根

GCC 的最新版本(包括版本 12)实现了过程间分析,该分析会严重损坏 ARM/Thumb 上系统调用存根的以下(仅限 GCC)代码。

typedef struct { int sender; int arg; } message;

#define syscall(op)  asm volatile ("svc %0" :: "i"(op))

#define SYS_SEND 9

#define NOINLINE __attribute((noinline))

void NOINLINE send(int dest, int type, message *msg)
{
    syscall(SYS_SEND);
}

void send_int(int d, int t, int v)
{
    message msg;
    msg.arg = v;
    send(d, t, &msg);
}
Run Code Online (Sandbox Code Playgroud)

目的是操作系统的陷阱处理程序将send通过访问参数寄存器的保存值来找到三个参数r0——r2在陷阱的异常帧中。问题显然是优化器在查看 的主体时send认为其消息参数的字段未被使用。msg.arg因此,主体中对 的赋值send_int被删除。这是通过编译上述源代码揭示的

arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -O -g -Wall -ffreestanding -c …
Run Code Online (Sandbox Code Playgroud)

c optimization gcc arm inline-assembly

2
推荐指数
1
解决办法
124
查看次数

标签 统计

arm ×1

c ×1

gcc ×1

haskell ×1

inline-assembly ×1

optimization ×1