c++ - How will be a reference treated in these cases? -


i know when reference parameter of function , function inlined, possible reference referent , not pointer it, when reference not parameter local function or global, or output of function inlined:

//global scope  void somefunc(sometype & ref){//when function inline, it's possible ref referent  //function body } int num=7; int & ref=num;//what ref here? void somefunc1(){  int num=6;  int & ref=num;//what ref here?  //rest of function body } int & somefunc2(){//what output reference here when function inlined, num or pointer ?  int num=8;  return num; } 

david rodríguez - dribeas pointed out in comment standard gives compilers quite bit of latitude, when comes references. may or may not take space; they're not proper objects themselves, etc.

the behavior describe function arguments of reference type (eliminated during inlining) typical freedom compilers have when comes references. it's freedom, not obligation them. may not possible either: when call somefunc( a>5 ? foo : bar); compiler unable replace reference "the" referent itself.

your other examples unconstrained. global , local references can optimized out, in theory, because there's nothing stop it. last example can entirely inlined exit(nasaldemons()); because you're returning reference object went out of scope.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -