的printf(QUOT;%d%d%d")
亲爱的,
考虑:
包括< stdio.h>
int main( void)
{
printf("%d%d%d");
return(0);
}
我正在努力向某人(其他地方)解释为什么
上述代码违反约束条件并因此需要a
(实现定义)警告。
我已经引用了关于stdio.h的标准部分,他们在哪里
明确声明如果
格式的参数不足,则行为未定义。
他的论点是:
- 未定义的行为并不意味着违反约束
- 我不能说出他为什么错了
- gcc没有发出任何警告使用-std = c99
-我迷路了......我告诉他GCC包括一个警告开关
( - Wformat)实际上给出了警告g代表上面的代码,并且'
罚款,因为标准只是说实现必须给出
警告,但是并没有规定如何,使用哪些标志,....
请你有任何其他措辞/例子/方式解释这个
人为什么代码是一个约束违规,为什么它需要
警告以及为什么GCC可以通过-Wformat发出此警告?
非常感谢!
- -
Pietro Cerutti
Dear all,
Consider:
include <stdio.h>
int main(void)
{
printf("%d%d%d");
return (0);
}
I''m having a bad time trying to explain someone (elsewhere) why the
aforementioned code is a constraint violation and thus requires a
(implementation defined) warning.
I have cited the part of the standard about stdio.h, where they
explicitly state that "If there are insufficient arguments for the
format, the behavior is undefined."
He''s arguments have been:
- a undefined behavior doesn''t imply a constraint violation
-I can''t word out why he''s wrong
- gcc doesn''t give any warnings using -std=c99
-I''m lost... I have told him that GCC includes a warning switch
(-Wformat) which actually gives a warning for the code above, and that''s
fine since the standard just says that the implementation has to give a
warning, but doesn''t dictate how, using which flags, ....
Please, do you have any other wording / examples / way to explain this
person why the code is a constraint violation, why it does require a
warning and why GCC is ok by issuing this warning with -Wformat?
Thanks a lot!
--
Pietro Cerutti
Pietro Cerutti写道:
)考虑:
)
)包括< stdio.h>
)int main(无效)
){
)printf("%d%d%d");
)return(0);
)}
未定义的行为,是的。阅读...
)我正在努力向某人(其他地方)解释为什么
)上述代码违反约束因此需要一个
)(实现定义)警告。
)
)我引用了关于stdio.h的标准部分,在哪里他们
)明确声明如果
格式的参数不足,则行为未定义。
)
)他的论点是:
) - 未定义的行为并不意味着违反约束
) - 我可以不知道为什么他错了
这可能是因为他是对的。
否则,i = i ++必须生成一个诊断同样。
) - gcc没有给出任何警告 - -dd = c99
) - 我迷路了......我有告诉他GCC包含一个警告开关
)( - Wformat)实际上给出了一个警告上面的代码,并且'
)很好,因为标准只是说实现必须给出一个
)警告,但是没有决定如何,使用哪些标志,....
如果标准sais实施必须给出诊断,
意味着你*不要*必须有任何额外的标志来表示
诊断。只是让它符合标准的旗帜。
所以他再次正确。
)请你还有其他措辞吗? / examples /解释这个问题的方法
)为什么代码是违反约束的人,为什么它需要
)警告以及为什么GCC可以发出此警告-Wformat?
你是对的,这不是违反约束的行为。会足够的。 ;-)
SaSW,Willem
-
免责声明:我不对任何陈述负责
在上文中提出。据我所知,我可能会被吸毒或者吸毒......
不,我不是偏执狂。你们都认为我是偏执狂,不是吗!
#EOT
Pietro Cerutti wrote:
) Consider:
)
) include <stdio.h>
) int main(void)
) {
) printf("%d%d%d");
) return (0);
) }
Undefined behaviour, yes. Reading on...
) I''m having a bad time trying to explain someone (elsewhere) why the
) aforementioned code is a constraint violation and thus requires a
) (implementation defined) warning.
)
) I have cited the part of the standard about stdio.h, where they
) explicitly state that "If there are insufficient arguments for the
) format, the behavior is undefined."
)
) He''s arguments have been:
) - a undefined behavior doesn''t imply a constraint violation
) -I can''t word out why he''s wrong
That may be because he is right.
Otherwise, i = i++ would have to generate a diagnostic as well.
) - gcc doesn''t give any warnings using -std=c99
) -I''m lost... I have told him that GCC includes a warning switch
) (-Wformat) which actually gives a warning for the code above, and that''s
) fine since the standard just says that the implementation has to give a
) warning, but doesn''t dictate how, using which flags, ....
If the standard sais that the implementation has to give a diagnostic,
that means you *don''t* have to have any extra flags to give said
diagnostic. Just the flags to make it standards conforming.
So he''s right again.
) Please, do you have any other wording / examples / way to explain this
) person why the code is a constraint violation, why it does require a
) warning and why GCC is ok by issuing this warning with -Wformat?
"You were right, it''s not a constraint violation." would be adequate. ;-)
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I''m not paranoid. You all think I''m paranoid, don''t you !
#EOT
Willem写道:
Willem wrote:
Pietro Cerutti写道:
)考虑:
)
)包括< stdio.h>
)int main(无效)
){
)printf("%d%d%d);
)返回(0);
)}
未定义的行为,是的。阅读...
)我正在努力向某人(其他地方)解释为什么
)上述代码违反约束因此需要一个
)(实现定义)警告。
)
)我引用了关于stdio.h的标准部分,在哪里他们
)明确声明如果
格式的参数不足,则行为未定义。
)
)他的论点是:
) - 未定义的行为并不意味着违反约束
) - 我可以不知道为什么他错了
这可能是因为他是对的。
否则,i = i ++必须生成一个诊断同样。
Pietro Cerutti wrote:
) Consider:
)
) include <stdio.h>
) int main(void)
) {
) printf("%d%d%d");
) return (0);
) }
Undefined behaviour, yes. Reading on...
) I''m having a bad time trying to explain someone (elsewhere) why the
) aforementioned code is a constraint violation and thus requires a
) (implementation defined) warning.
)
) I have cited the part of the standard about stdio.h, where they
) explicitly state that "If there are insufficient arguments for the
) format, the behavior is undefined."
)
) He''s arguments have been:
) - a undefined behavior doesn''t imply a constraint violation
) -I can''t word out why he''s wrong
That may be because he is right.
Otherwise, i = i++ would have to generate a diagnostic as well.
确实如此,至少使用-Wsequence-point。
It does, using at least -Wsequence-point.
>
) - gcc没有给出任何警告使用-std = c99
) - 我迷路了......我告诉他GCC包含一个警告开关
)( - Wformat)实际上是对上面的代码发出警告,那就是'br / >
)很好,因为标准只是说实施必须给出一个
)警告,但是并没有规定如何使用哪些标志......
如果标准sais实现必须提供诊断,
意味着你*不必*有任何额外的标志来表示
诊断。只是标志使标准符合要求。
>
) - gcc doesn''t give any warnings using -std=c99
) -I''m lost... I have told him that GCC includes a warning switch
) (-Wformat) which actually gives a warning for the code above, and that''s
) fine since the standard just says that the implementation has to give a
) warning, but doesn''t dictate how, using which flags, ....
If the standard sais that the implementation has to give a diagnostic,
that means you *don''t* have to have any extra flags to give said
diagnostic. Just the flags to make it standards conforming.
Sais是谁?该标准说以实现定义的方式。它
并没有进一步指示。我错过了什么吗?
Sais who? The standard says "in an implementation defined manner". It
doesn''t dictate any further. Am I missing anything?
SaSW,Willem
SaSW, Willem
-
Pietro Cerutti
--
Pietro Cerutti
Pietro Cerutti写道:
)Willem写道:
)这可能是因为他是对的。
)否则,i = i ++也必须生成诊断。
)
)确实如此至少-Wsequence-point。
是否有* all * undefined行为的警告标志?
请注意以下未定义的行为代码:
#include< stdio.h>
int main(无效)
{
char x [ 20] =一一一一;
char y [20] =" two two two two;
int i = 0;
for(i = 0; i< 40; i ++)
x [i] =''x'';
printf("%s, %s",x,y);
返回0;
}
(有趣的是,在我的实施中,这有不同使用或不使用优化编译
时的结果(gcc 4.2.1用于记录))
)>
)) - gcc没有发出任何警告使用-std = c99
)) - 我输了......我告诉他GCC包含一个警告开关
))( - Wformat)实际上给出了上面代码的警告,并且'
))很好,因为标准只是说实现必须给出一个
))警告,但并没有规定如何使用哪些标志......
)>
)如果标准sais表示执行必须给出一个诊断,
)这意味着你*不需要任何额外的标志来说明
)诊断。只是标志使其符合标准。
)
)Sais是谁?该标准说以实现定义的方式。它b / b $ b)并没有进一步决定。我错过了什么吗?
当您解释在实施中定义
方式时,您正在大跃进as你可能需要指定其他选项。
它只是意味着诊断的形式取决于
的实现。但*必须*发出* * *
SaSW,Willem
-
免责声明:我不承担任何责任上述文本中的陈述
。据我所知,我可能会被吸毒或者吸毒......
不,我不是偏执狂。你们都认为我是偏执狂,不是吗!
#EOT
Pietro Cerutti wrote:
) Willem wrote:
)That may be because he is right.
)Otherwise, i = i++ would have to generate a diagnostic as well.
)
) It does, using at least -Wsequence-point.
Is there a warning flag for *all* undefined behaviour ?
Note the following piece of undefined behaviour code:
#include <stdio.h>
int main(void)
{
char x[20] = "one one one one";
char y[20] = "two two two two";
int i = 0;
for (i = 0; i < 40; i++)
x[i] = ''x'';
printf("%s, %s",x , y);
return 0;
}
(Interestingly, on my implementation, this has different results when
compiled with or without optimization (gcc 4.2.1 for the record))
)>
)) - gcc doesn''t give any warnings using -std=c99
)) -I''m lost... I have told him that GCC includes a warning switch
)) (-Wformat) which actually gives a warning for the code above, and that''s
)) fine since the standard just says that the implementation has to give a
)) warning, but doesn''t dictate how, using which flags, ....
)>
)If the standard sais that the implementation has to give a diagnostic,
)that means you *don''t* have to have any extra flags to give said
)diagnostic. Just the flags to make it standards conforming.
)
) Sais who? The standard says "in an implementation defined manner". It
) doesn''t dictate any further. Am I missing anything?
You''re making a big leap when you interpret "in an implementation defined
manner" as "you may need to specify additional options".
It simply means that the form of the diagnostic is up to the
implementation. But it *must* issue *something*.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I''m not paranoid. You all think I''m paranoid, don''t you !
#EOT