stack

how to reference local variables on the stack properly

若如初见. 提交于 2019-12-24 01:45:18
问题 Enter in function, standard prologue push rbp mov rbp, rsp sub rsp, 128 ; large space for storing doubles, for example How to reference local variables now, via rsp + positive offset, or via rbp + negative offset? Reading https://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames, indeed quite understandable. It writes ...the value of esp cannot be reliably used to determine (using the appropriate offset) the memory location of a specific local variable. To solve this problem,

getaddrinfo addrinfo result in stack or heap

假如想象 提交于 2019-12-23 21:52:11
问题 I am a bit confused at least. getaddrinfo() call 'updates' a pointer to a addrinfo struct, all is well when I am going to use the addrinfo in the same scope (that function) but what happens if I copy the struct to another one (by assigning it). Please help me understand the undergoing basics (not seeking advice for alternative approaches). Correct me if I am wrong: a) getaddrinfo() requires a pointer to struct-pointer to addrinfo. b) getaddrinfo creates a addrinfo struct in the current

when the c++ program stack size used is determined?

↘锁芯ラ 提交于 2019-12-23 20:24:23
问题 I know the maximum stack size usually is fixed on link (maybe on windows is that). But I don't know when the program stack size ( not maximum stack size just used size) used is be fixed to OS. compile ? linked ? execute ? like this: int main(){ int a[10]; return 0;} the program just use 10 * sizeof(int) stack. so, is the stack size fixed? above all. if the heap size is changed when malloc or free? 回答1: Stack size is not explicitly provided to OS, when program is loaded. Instead, OS uses

Why an uninitialized variable in C still produces output

烈酒焚心 提交于 2019-12-23 19:23:46
问题 I'm trying to figure out why even though the local variable i is never intialized in this C program, many systems will print out 0 1 2 3 4 5 6 7 8 9 Can someone explain why this is? Any help is appreciated! void foo() { int i; printf("%d ", i++); } int main() { int j; for (j = 1; j <= 10; j++) foo(); } 回答1: The behavior is undefined. The statistics are irrelevant. It might be because of the layout and the initialization of the stack, but it might be for any other reason as well. For example,

inspect.currentframe() may not work under some implementations?

早过忘川 提交于 2019-12-23 17:43:19
问题 According to the docs: inspect.currentframe() Return the frame object for the caller’s stack frame. CPython implementation detail: This function relies on Python stack frame support in the interpreter, which isn’t guaranteed to exist in all implementations of Python. If running in an implementation without Python stack frame support this function returns None. How is it that only this function is marked as "implementation-dependent"? If this function doesn't work, wouldn't similar functions,

Making a heap copy of a struct in D

我们两清 提交于 2019-12-23 15:37:11
问题 How can I create a garbage-collected copy of a struct that's on the stack? Coming from a C++ background, my first guess would be a copy constructor like the one below, but it doesn't seem very idiomatic for D, and I haven't seen one in any of the D projects I've taken a look at. struct Foo { immutable int bar; this(int b) { bar = b; } // A C++-style copy constructor works but doesn't seem idiomatic. this(ref const Foo f) { bar = f.bar; } } void main() { // We initialize a Foo on the stack

why its not safe to return value on function stack

。_饼干妹妹 提交于 2019-12-23 14:58:11
问题 I came across the following paragraph while reading bruce eckel..where he was trying to explain why its not safe for function to return value on stack Now imagine what would happen if an ordinary function tried to return values on the stack .you can,t touch any part of the stack that's above the return address,so the function would have to push the values below the return address. But when the assembly language return is executed ,the stack pointer must be pointing to the return address(or

Is there a way to apply the Knuth shuffle to a Stack data structure?

浪子不回头ぞ 提交于 2019-12-23 14:37:11
问题 For a programming class I am creating a blackjack program for the first homework assignment. The professor has given us a sample Card class, which includes the method to add them to a deck. For her deck, she uses an ArrayList, which you can easily Knuth Shuffle with the Collections.shuffle() method. That method does not work for Stacks though (obviously), but I think a Stack structure would work best for this program because you may pop and push cards into and out of the deck. 回答1: Both java

Ruby: extract features of a Stack from the Array class

一世执手 提交于 2019-12-23 13:06:53
问题 I have the need to use a Stack-like data structure for a program that I am writing and I know that Ruby doesn't have an explicit Stack data-structure, but that the Array class has all of the properties that make a Stack: push , pop , size , clear , isEmpty , inspect , to_s . In searching online I found various posts using this syntax to extract features of the Array class into a subclass: Stack = Array.extract([ :push, :pop, :size, :clear, :inspect, :to_s ]) s = Stack.new s.push 1 s.push 2 s

What's wrong with my maze checker??? (JAVA)

社会主义新天地 提交于 2019-12-23 11:57:56
问题 So we are given a maze with walls(W) open path(O) a start pt (S) and a finish pt (F). I am trying to write an algorithm that takes the maze file and then turns it into a 2D array of points to make a grid. Once I have the grid, I want to start on the 'S' character in the maze and try to find whether or not it is possible to traverse through the O's to get to the F. (Return a boolean true/false) I know that this maze is solvable, so why am I getting 'false'?? There must be a complicate problem