I am taking the first dive into the waters of stack memory trace so I need your help. Here is my problem for which I need your tips:
I have two functions: login and logout(). There is one simple condition:
I believe that that I can not do it on compile time so I have to do it on runtime(I can be wrong).
The problem is that how do I find out that logout() is called in my program before the main() returns and generate error if it is not called.
I was thinking that at the runtime, Every function that I call after login() should check whether it is the last function call and then look whether the logout() was called ever before or not.
So How would I know at runtime that a certain function is the last function my program called before the main() returns?
Any help would be appreciated.
one way, perhaps not the nicest, is to use a variable loggedIn = 1, and pass a reference to it so logout() can set it to zero. check that it's zero before return from main().
after a function returns, its address has already been popped from the stack.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.