News for hackers. Stuff that matters.
Re:The Little C Function From Hell by vhf on Tuesday June 19, 2012 @09:59AM (#4131820)
It is the opposite, like in many other languages. e.g.

  int i = 0;
  printf("%i %i", i++, ++i); // prints "0 2"
Same goes in C, C++, Java, PHP, ...

[EDIT] Turns out this is a bad example, as "the order in which function arguments are evaluated is undefined" (cf. below) Correct is :

  int i = 0;
  printf("%i", i++); // prints 0
  printf("%i", ++i); // prints 2
Re:The Little C Function From Hell by decklin on Tuesday June 19, 2012 @10:05AM (#4131861)
Actually, the order in which function arguments are evaluated is undefined. http://c-faq.com/expr/comma.html

You can use a comma in other expressions to introduce a sequence point: http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr#seqpoints

Re:The Little C Function From Hell by vhf on Tuesday June 19, 2012 @10:15AM (#4131912)
Thanks for your clever comment and for those emitting similar concerns.

You surely are right. I wanted to give a quick example, turns out it was a bad one. Next time I'll write :

  int i = 0;
  printf("%i", i++); // prints 0
  printf("%i", ++i); // prints 2
Re:The Little C Function From Hell by hythloday on Tuesday June 19, 2012 @11:02AM (#4132147)
turns out it was a bad one

Given that you were making a point on an article about the complexity of C, I'd say it was an unintentionally excellent example.

Re:The Little C Function From Hell by sirclueless on Tuesday June 19, 2012 @03:02PM (#4133542)
If you really want to make your brain hurt, there was an article on HN a while ago about the following statement:

    i = i++;
Evaluating that expression takes a real dive into the guts of the C spec.
Re:The Little C Function From Hell by simias on Tuesday June 19, 2012 @10:03AM (#4131848)
I believe you trigger an undefined behaviour there. You modify i twice in the same statement.
Re:The Little C Function From Hell by jim_kaiser on Tuesday June 19, 2012 @12:45PM (#4132756)
The standard says, evaluation order of function arguments is undefined.. but in general, printf evaluates right to left. This was a common puzzle as I remember.
Re:The Little C Function From Hell by excuse-me on Tuesday June 19, 2012 @10:04AM (#4131852)
Is that defined behaviour?

Is there any rule saying that args to a function have to be evaluated in a particular order - ie is ',' a function point?