stack

Why is my compiler reserving more space than required for a function stack frame?

廉价感情. 提交于 2019-12-12 07:56:12
问题 I have a function: void func(int a) { int x = a+2; } In the assembly code, in function prolog: push %ebp mov %esp, %ebp sub $0x10, %esp The code only needs to reserve space for x i.e. 4 bytes. But it is reserving 16 bytes. Why is that ? I have always seen it to reserve more space than required. My guess: it tends to store in 16 bytes. i.e. if I needed say 20 bytes, it will reserve 32 bytes, no matter what. 回答1: This highly depends on your architecture and compiler flags, so it is impossible

Reversing word with Stack

流过昼夜 提交于 2019-12-12 06:48:07
问题 I am not sure why this is giving me an error. I am in the method pop and i want to return the value stored at the position top. Though it says they are incompatible types. I do not see why it should be a problem as I only want the character to be printed out at the position. This is part of a bigger program just so you know and will be getting the word from a different class. public class Stack { private int maxSize; private String[] stackArray; private int top; /** * Constructor for objects

convert infix to Rpn (shunting yard)

て烟熏妆下的殇ゞ 提交于 2019-12-12 05:15:16
问题 here is my code to convert infix to ron using shunting yard . I know how the algorithm works well and I have no problem with that . but when I run this just nothing happen . when I debug it I get unknown error on stack initialization line #include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <stack> using namespace std ; void convert (char *) ; double eval(char *) ; int precedence(char); int main() { cout << "\n Enter an expression :\n" ; cout << " >> " ; char

Stack order when calling anonymous functions in Javascript/Node.JS

爷,独闯天下 提交于 2019-12-12 04:34:31
问题 How does stack order work in javascript when using anonymous functions? I would expect the following code to print: "first call second call third call", but instead it prints: "second call third call first call". function findTweets(params, num) { params = { q: params, count: num , language: 'en' } T.get('search/tweets', params, function(err, data, response) { console.log("first call"); }); console.log("second call"); } findTweets("a str",1) console.log("third call"); Any help would be

Calculating number of three consecutive values above a threshold (in raster stack)

老子叫甜甜 提交于 2019-12-12 04:34:14
问题 I need to compute number of three consecutive days when value of each pixel in a raster stack ( x ) is above a given threshold (defined by another raster y ). I tried using rle for the purpose with calc as follows after stacking x and y together into new raster a : library(raster) fn<-function(a) with(rle(a), sum(lengths>=3 & values>a[[nlayers(a)]])) calc(b,fn) However, I am getting the error: Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply) : cannot use this function Reproducible

Declaration of array in c [duplicate]

假装没事ソ 提交于 2019-12-12 04:14:43
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Stack variables vs. Heap variables What is the difference between declaring an array as: int arr[100]; and int* arr=(int*)malloc(sizeof(int)*100); Which one is preferred? Is there something like heap and stack memory involved in this? 回答1: I suggest a trip to the bookstore to pickup a copy of Kernighan and Ritchie's The C Programming Language , and optionally, a copy of Harbison & Steele's C: A Reference Manual

'undefined' - if it's defined as a primitive value, what is it defined in terms of its value at the memory level?

半城伤御伤魂 提交于 2019-12-12 04:07:28
问题 I understand from MDN that 'undefined' is recognised as a primitive value, which is corroborated by the ES doco also stating that an "undefined value" is a "primitive value used when a variable has not been assigned a value ". I also understand even though the variable may not be assigned a value (i.e. an uninitialised variable), memory is still allocated for it during the creation of its execution context ('creation' phase) prior to execution happening. This explains why when we attempt to

How can I instantiate an array of Stacks of type int?

依然范特西╮ 提交于 2019-12-12 03:57:40
问题 I am trying to create an array of stacks, in which each stack within the array is of type int . If I create the array like this: Stack<Integer>[] numbers = new Stack<Integer>[3]; , there is the compile error " Cannot create a generic array of Stack<Integer> ". So, I am trying to create the array of Stacks with the wildcard type instead of Integer , and it then does not have this error. However, if I then try to push an int into one of the stacks (of wildcard " ? " type) like this: this

[C++]How to use std::stack to deal with the file/directory hierarchy?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 03:57:07
问题 I have 3 class, Root, CFile, SubDirectory. Root is a abstract class. CFile and SubDirectory are derived from Root. CFile has attributes: name:string , size:int, level:int. SubDirectory has attributes: name:string, size:int, level:int,a vector, which contains both files and directories and a function void add() to push the file or directory into the vector. If a file in a directory, file's level is higher than the directory's by one. All setters and getters are defined. Now, I have a file

Memory leak in basic stack

给你一囗甜甜゛ 提交于 2019-12-12 03:37:17
问题 I'm working on a real simple stack implementation, and I can't seem to figure out why I have a memory leak. What I expect from the code is that 5 nodes are allocated in push() and 5 nodes are freed in displayAndDestroy(). But Valgrind says I've allocated 6 nodes worth of data and only freed 5. I've been staring at this for a while and I'm not exactly sure where I went wrong. #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct STACK{ char data[100]; struct STACK *next; }