函数调用中的大括号在 C 中意味着什么?

What curly braces inside a function call mean in C?

我试图解决 K&R C 书中的练习 1-24,您必须在其中创建一个可以检测基本语法错误(不平衡的括号、方括号等)的程序。我 运行 进行了一些测试,以对分散在我系统上的 C 源文件进行调试。 我的程序在文件中遇到这一行时检测到错误:

av_opt_set_q  (abuffer_ctx, "time_base", (AVRational ){ 1, INPUT_SAMPLERATE }, AV_OPT_SEARCH_CHILDREN);

我做了一个假设,每次遇到正则大括号(外注释,双引号),小括号和中括号都要平衡。正如此错误所示,这是不正确的。不幸的是我找不到它的意思。谢谢你的帮助。

这个

 (AVRational ){ 1, INPUT_SAMPLERATE }

是一个compound literal. Check more about it here

来自 C11,章节 §6.5.2.5

A postfix expression that consists of a parenthesized type name followed by a brace-enclosed list of initializers is a compound literal. It provides an unnamed object whose value is given by the initializer list.

也就是说,我看不出这里的牙套不平衡。这是一个有效的语法,您的工具在做出决定时应该考虑到这一点。