Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Ok, engaging lawyer mode. ISO C99 standard says, in 6.5 (2):

Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.
Failing the above rule, behavior is undefined. However, regarding initializer lists, read this, this question, and this this report. Various C and C++ standards differ in their wording, and guarantees they make. Coming back to C99, 6.7.8 (19) says:
The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject; ...
But then, 6.7.8 (23)
The order in which any side effects occur among the initialization list expressions is unspecified.

This example code is valid in C99 (no undefined behaviour), yet what it prints is unspecified.

#include <stdio.h> void meh(int t[]) { int i = 0; int foo[] = { [1] = ++i, [2] = ++i, [0] = ++i }; for (i = 0; i < 3; i++) { t[i] = foo[i]; } } int main(void) { int x[3]; meh(x); printf("%d %d %d\n", x[0], x[1], x[2]); }

For perl, flexibility in constructing and manipulating lists, e.g. using iterators (with their side effects) and so on, is essential quality of the language. There is no undefined behavior here. This thing quacks like a bug, it is a bug. How much speed-up do you think this buggy optimization is worth?


In reply to Re^5: Why does the first $c evaluate to the incremented value ... (bug) by oiskuu
in thread Why does the first $c evaluate to the incremented value in [$c, $c += $_] ? by smls

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-24 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found