strict aliasing - Is this short program legal C++? -


while solving test on http://cppquiz.org found interesting piece of code :

#include <iostream>  int f(int& a, int& b) {     = 3;     b = 4;     return + b; }  int main () {     int = 1;     int b = 2;     int c = f(a, a);// note a,a     std::cout << << b << c; } 

my question program legal c++ or isnt? im concerned strict aliasing.

you mention strict aliasing – but strict aliasing concerned aliases of different types. doesn’t apply here.

there’s no rule forbids code. it’s moral equivalent of following code:

int x = 42; int& y = x; int& z = x; 

or, more relevantly, it’s equivalent having several child nodes refer same parent node in tree data structure.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -