Advertisement
alexanius

strict-aliasing violation in stl

Oct 3rd, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. struct TreeNodeBase
  2. {
  3.     int color;
  4.     TreeNodeBase *parent;
  5.     TreeNodeBase *left;
  6.     TreeNodeBase *right;
  7. };
  8.  
  9. struct TreeNode : public TreeNodeBase
  10. {
  11.     double value;
  12. };
  13.  
  14. struct Tree
  15. {
  16.     TreeNodeBase header;
  17.     unsigned long node_count;
  18. };
  19.  
  20. extern void side_effect(Tree *);
  21.  
  22. double write_eps(int n)
  23. {
  24.     Tree cells;
  25.     cells.node_count = 0;
  26.     cells.header.color = 0;
  27.     cells.header.parent = 0;
  28.     cells.header.left = &cells.header;
  29.     cells.header.right = &cells.header;
  30.  
  31.     for (int i = 0; i < n; ++i)
  32.     {
  33.         side_effect(&cells);
  34.     }
  35.  
  36.     return static_cast<TreeNode*>(cells.header.left)->value;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement