You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询C标准中字符串拼接行为的定义位置及搜索术语

String Literal Concatenation in C: Standard Definition and Search Term

Great question—this is a common point of confusion, but it’s absolutely defined by the C standard, not the pr_info macro. Let’s break this down clearly:

This behavior is officially called string literal concatenation—that’s the exact phrase you’ll want to use when looking up documentation, tutorials, or standard references.

Where It’s Defined in the C Standard

In the C11 standard (the most widely adopted modern version of the spec), this rule is spelled out in section 6.4.5 (String literals), paragraph 6:

In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and wide string literals are concatenated into a single multibyte character sequence. If any of the literals is a wide string literal, the resulting multibyte character sequence is treated as a wide string literal; otherwise, it is treated as a character string literal.

In plain terms: during compilation (specifically the sixth phase of code translation), the compiler automatically merges any adjacent string literals (like "aaa" and "bb" in your test code) into one continuous string. No operators or macros are required—this is a core part of how the C language processes string literals.

How It Applies to Your Xtables Code

In the line you encountered:

pr_info("SRC=" NIP6_FMR "DST=" NIP6_FMR "\n", NIP6(iph->saddr), NIP6(iph->daddr));

NIP6_FMR is a preprocessor macro that expands to a string literal (likely a format string for IPv6 address formatting, like "%02x%02x:%02x%02x:...). Since macro expansion happens before translation phase 6, the line becomes a sequence of adjacent string literals, which the compiler then concatenates into one single format string. The pr_info macro has no role in the concatenation—it just receives the final merged string as its first argument.

Quick Additional Notes

  • No whitespace is added between concatenated literals: "hello" "world" becomes "helloworld", not "hello world". You need to include spaces explicitly in the literals if you want them.
  • Mixing narrow string literals (regular "...") and wide string literals (L"...") in a concatenation is a compiler error—they must be the same type.

内容的提问来源于stack exchange,提问作者q2ven

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:31:16