Is this undefined behavior in C/C++ (Part 2)

This question already has an answer here:

  • Why are these constructs (using ++) undefined behavior in C? 13 answers
  • Undefined behavior and sequence points 4 answers

  • It's undefined because of 2 reasons:

  • The value of i is twice used without an intervening sequence point (the comma in argument lists is not the comma operator and does not introduce a sequence point).

  • You're calling a variadic function without a prototype in scope.

  • The number of arguments passed to printf() are not compatible with the format string.

  • the default output stream is usually line buffered. Without a 'n' there is no guarantee the output will be effectively output.


  • 所有参数在调用函数时都会被计算,即使它们没有被使用,所以,由于函数参数的计算顺序是未定义的,所以您再次使用UB。


    I think it's well defined. The printf matches the first % placeholder to the first argument, which in this instance is a preincremented variable.

    链接地址: http://www.djcxy.com/p/73240.html

    上一篇: 单个语句中的多个增量运算符

    下一篇: 这是C / C ++中未定义的行为(第2部分)