是否有一个开关可以用 clang 禁用三字母?

发布于 2025-01-08 04:54:15 字数 680 浏览 3 评论 0原文

我第一次使用 clang 构建了一些(遗留)代码。代码类似于:

sprintf(buf, "%s <%s ????>", p1, p2);

Clang 给出以下警告(-Werror 错误):

test.c:6:33: error: trigraph converted to '}' character [-Werror,-Wtrigraphs]
    sprintf(buf, "%s <%s ????>", p1, p2);
                           ^

显然 ??> 并不打算作为三字母,所以我想禁用完全是三字母组(来源并没有故意在任何地方使用它们)。

我已经尝试过 -no-trigraphs 但这并不是一个真正的选择:

clang: warning: argument unused during compilation: '-no-trigraphs'

我可以使用 -Wno-trigraphs 关闭三字母警告,但我不希望三字母转换为实际上发生了。

注意:启用三字母是使用 -std=c89 的意外副作用。

I've got some (legacy) code that I'm building with clang for the first time. The code is something like:

sprintf(buf, "%s <%s ????>", p1, p2);

Clang gives the following warning (error with -Werror):

test.c:6:33: error: trigraph converted to '}' character [-Werror,-Wtrigraphs]
    sprintf(buf, "%s <%s ????>", p1, p2);
                           ^

Clearly the ??> is not intended as a trigraph, so I want to disable trigraphs entirely (the source does not intentionally use them anywhere).

I have tried -no-trigraphs but that's not really an option:

clang: warning: argument unused during compilation: '-no-trigraphs'

I can turn off the trigraphs warning with -Wno-trigraphs but I don't want the trigraph conversion to actually take place at all.

NOTE: Trigraphs were enabled as an unintended side effect of using -std=c89.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪冰清 2025-01-15 04:54:15

尝试使用 gnu* 模式 - “Trigraphs 默认在 gnu* 模式下关闭;可以通过 -trigraphs 选项启用它们。” (有关其他差异,请参阅 http://clang.llvm.org/docs/UsersManual.html#c_modes和命令行开关)

Try using gnu* mode - "Trigraphs default to being off in gnu* modes; they can be enabled by the -trigraphs option." (see http://clang.llvm.org/docs/UsersManual.html#c_modes for other differences and command line switch)

国粹 2025-01-15 04:54:15

我看不到禁用三字母组合的明显方法(而不是三字母组合警告)。修复此代码的最简单方法可能是将其更改为:

sprintf(buf, "%s <%s ????"">", p1, p2);

I couldn't see an obvious way to disable trigraphs (rather than the trigraphs warning). Probably the easiest way to fix this code is to change it to:

sprintf(buf, "%s <%s ????"">", p1, p2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文