Recursive calls to a function - why is the address of the parameter passed to it lowering with each call? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!What is the direction of stack growth in most modern systems?Why isn't sizeof for a struct equal to the sum of sizeof of each member?How to call a parent class function from derived class function?Why do we need virtual functions in C++?Pretty-print C++ STL containersHow to pass normal param as well as template param in a template function in C++?Are the days of passing const std::string & as a parameter over?Recursive Reverse FunctionWhy can I not move unique_ptr from a set to a function argument using an iterator?Why can I not call reserve on a vector of const elements?Having issues with .h file, it doesn't seem to be linking correctly

What helicopter has the most rotor blades?

lm and glm function in R

How do I overlay a PNG over two videos (one video overlays another) in one command using FFmpeg?

Reflections in a Square

“Since the train was delayed for more than an hour, passengers were given a full refund.” – Why is there no article before “passengers”?

Book about a teenager and alien

Does traveling In The United States require a passport or can I use my green card if not a US citizen?

Does using the inspiration rules for character defects tend to encourage players to display MGS?

/bin/ls sorts differently than just ls

Putting Ant-Man on house arrest

Trying to enter the Fox's den

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

Can I ask an author to send me his ebook?

Is there a way to convert Wolfram Language expression to string?

Is it OK if I do not take the receipt in Germany?

Are Flameskulls resistant to magical piercing damage?

Why does BitLocker not use RSA?

Network questions

Short story about an alien named Ushtu(?) coming from a future Earth, when ours was destroyed by a nuclear explosion

What documents does someone with a long-term visa need to travel to another Schengen country?

Who can become a wight?

xkeyval -- read keys from file

reduction from 3-SAT to Subset Sum problem

Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?



Recursive calls to a function - why is the address of the parameter passed to it lowering with each call?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!What is the direction of stack growth in most modern systems?Why isn't sizeof for a struct equal to the sum of sizeof of each member?How to call a parent class function from derived class function?Why do we need virtual functions in C++?Pretty-print C++ STL containersHow to pass normal param as well as template param in a template function in C++?Are the days of passing const std::string & as a parameter over?Recursive Reverse FunctionWhy can I not move unique_ptr from a set to a function argument using an iterator?Why can I not call reserve on a vector of const elements?Having issues with .h file, it doesn't seem to be linking correctly



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








7















Consider following code:



#include <iostream>
using namespace std;
void test_func(int address)
cout<<&address<<" ";
if(address < 0x7FFBEE26)
test_func(address);


int main()

test_func(512);
cout<<"Hello";
return 0;



Hello from main() is certainly not reached, since the recursive calls to test_func never end.



However, from what I can see in the cout present in test_func - the addresses being printed are lower and lower with each iteration. Why is that happening?










share|improve this question









New contributor




tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    You are passing a copy - that has to have an address

    – UnholySheep
    1 hour ago






  • 1





    Remember that the default stack size on linux is 10MB and its 1 MB on windows. Also the stack need not be in the same location each time you run your program.

    – drescherjm
    1 hour ago












  • I can't understand why this isn't eligible for tail-call optimization. The invocation of test_func is the last line in the function...

    – cyberbisson
    50 mins ago


















7















Consider following code:



#include <iostream>
using namespace std;
void test_func(int address)
cout<<&address<<" ";
if(address < 0x7FFBEE26)
test_func(address);


int main()

test_func(512);
cout<<"Hello";
return 0;



Hello from main() is certainly not reached, since the recursive calls to test_func never end.



However, from what I can see in the cout present in test_func - the addresses being printed are lower and lower with each iteration. Why is that happening?










share|improve this question









New contributor




tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    You are passing a copy - that has to have an address

    – UnholySheep
    1 hour ago






  • 1





    Remember that the default stack size on linux is 10MB and its 1 MB on windows. Also the stack need not be in the same location each time you run your program.

    – drescherjm
    1 hour ago












  • I can't understand why this isn't eligible for tail-call optimization. The invocation of test_func is the last line in the function...

    – cyberbisson
    50 mins ago














7












7








7








Consider following code:



#include <iostream>
using namespace std;
void test_func(int address)
cout<<&address<<" ";
if(address < 0x7FFBEE26)
test_func(address);


int main()

test_func(512);
cout<<"Hello";
return 0;



Hello from main() is certainly not reached, since the recursive calls to test_func never end.



However, from what I can see in the cout present in test_func - the addresses being printed are lower and lower with each iteration. Why is that happening?










share|improve this question









New contributor




tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Consider following code:



#include <iostream>
using namespace std;
void test_func(int address)
cout<<&address<<" ";
if(address < 0x7FFBEE26)
test_func(address);


int main()

test_func(512);
cout<<"Hello";
return 0;



Hello from main() is certainly not reached, since the recursive calls to test_func never end.



However, from what I can see in the cout present in test_func - the addresses being printed are lower and lower with each iteration. Why is that happening?







c++






share|improve this question









New contributor




tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









drescherjm

6,59923553




6,59923553






New contributor




tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









tears allotears allo

361




361




New contributor




tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






tears allo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1





    You are passing a copy - that has to have an address

    – UnholySheep
    1 hour ago






  • 1





    Remember that the default stack size on linux is 10MB and its 1 MB on windows. Also the stack need not be in the same location each time you run your program.

    – drescherjm
    1 hour ago












  • I can't understand why this isn't eligible for tail-call optimization. The invocation of test_func is the last line in the function...

    – cyberbisson
    50 mins ago













  • 1





    You are passing a copy - that has to have an address

    – UnholySheep
    1 hour ago






  • 1





    Remember that the default stack size on linux is 10MB and its 1 MB on windows. Also the stack need not be in the same location each time you run your program.

    – drescherjm
    1 hour ago












  • I can't understand why this isn't eligible for tail-call optimization. The invocation of test_func is the last line in the function...

    – cyberbisson
    50 mins ago








1




1





You are passing a copy - that has to have an address

– UnholySheep
1 hour ago





You are passing a copy - that has to have an address

– UnholySheep
1 hour ago




1




1





Remember that the default stack size on linux is 10MB and its 1 MB on windows. Also the stack need not be in the same location each time you run your program.

– drescherjm
1 hour ago






Remember that the default stack size on linux is 10MB and its 1 MB on windows. Also the stack need not be in the same location each time you run your program.

– drescherjm
1 hour ago














I can't understand why this isn't eligible for tail-call optimization. The invocation of test_func is the last line in the function...

– cyberbisson
50 mins ago






I can't understand why this isn't eligible for tail-call optimization. The invocation of test_func is the last line in the function...

– cyberbisson
50 mins ago













1 Answer
1






active

oldest

votes


















11














Likely address is being placed on the stack and, on your platform, the stack grows downward in memory. See this question about stack growth direction for more.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    tears allo is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55800947%2frecursive-calls-to-a-function-why-is-the-address-of-the-parameter-passed-to-it%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    11














    Likely address is being placed on the stack and, on your platform, the stack grows downward in memory. See this question about stack growth direction for more.






    share|improve this answer



























      11














      Likely address is being placed on the stack and, on your platform, the stack grows downward in memory. See this question about stack growth direction for more.






      share|improve this answer

























        11












        11








        11







        Likely address is being placed on the stack and, on your platform, the stack grows downward in memory. See this question about stack growth direction for more.






        share|improve this answer













        Likely address is being placed on the stack and, on your platform, the stack grows downward in memory. See this question about stack growth direction for more.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        David SchwartzDavid Schwartz

        140k14145232




        140k14145232






















            tears allo is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            tears allo is a new contributor. Be nice, and check out our Code of Conduct.












            tears allo is a new contributor. Be nice, and check out our Code of Conduct.











            tears allo is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55800947%2frecursive-calls-to-a-function-why-is-the-address-of-the-parameter-passed-to-it%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Are there any AGPL-style licences that require source code modifications to be public? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Force derivative works to be publicAre there any GPL like licenses for Apple App Store?Do you violate the GPL if you provide source code that cannot be compiled?GPL - is it distribution to use libraries in an appliance loaned to customers?Distributing App for free which uses GPL'ed codeModifications of server software under GPL, with web/CLI interfaceDoes using an AGPLv3-licensed library prevent me from dual-licensing my own source code?Can I publish only select code under GPLv3 from a private project?Is there published precedent regarding the scope of covered work that uses AGPL software?If MIT licensed code links to GPL licensed code what should be the license of the resulting binary program?If I use a public API endpoint that has its source code licensed under AGPL in my app, do I need to disclose my source?

            2013 GY136 Descoberta | Órbita | Referências Menu de navegação«List Of Centaurs and Scattered-Disk Objects»«List of Known Trans-Neptunian Objects»

            Metrô de Los Teques Índice Linhas | Estações | Ver também | Referências Ligações externas | Menu de navegação«INSTITUCIÓN»«Mapa de rutas»originalMetrô de Los TequesC.A. Metro Los Teques |Alcaldía de Guaicaipuro – Sitio OficialGobernacion de Mirandaeeeeeee