Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Stack Data Allocation

$
0
0

In Visual Studio 2013, C++, unmanaged code, I have a function like

void     SomeFunc()

{

            if (…some condition…) {

                       int        x;

                       // do some stuff with x

            } else {

                       int        y;

                       // do some stuff with y

            }

} // end SomeFunc

Are x and y both allocated on the stack on every call, or is each variable allocated when and if its branch is taken? For integer variables this is not very important, but I want to understand the behavior in the general case, in which branches may have lots of stack data, including non-trivial objects. Thanks.


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>