返回资讯中心
外部精选
软件工程
#开发者实时流

Nine ways to break your systems code using volatile (2010)

Regarding the example #5, I must be confused about the definition of a sequence point because the resulting assembly output seems to be non-ANSI C:

Hacker News 最新andsoitis2026/11/1 · 今天2 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

Regarding the example #5, I must be confused about the definition of a sequence point because the resulting assembly output seems to be non-ANSI C:

void foo (int i) {

message[i/10] = 42;

ready = 1;

}

The full statement, message[i/10] = 42; is a sequence point. My understanding is that the fact that it is a sequence point ensures that it will be performed prior to the next line of code. So how can 1 be moved into “ready” prior to 42 being assigned the the message[] array, as your assembly output shows?

foo:

movl $1, ready

…

movl $42, message(,%edx,4)

ret

Your clarification is appreciated because it appears I don’t fully understand the purpose or behavior of a sequence point. It seems to me, if the lines of code in a function can be evaluated in any order, nothing would run.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →