stack

How to traverse stack in C++?

被刻印的时光 ゝ 提交于 2019-12-05 06:40:54
Is it possible to traverse std::stack in C++? Traversing using following method is not applicable. Because std::stack has no member end . std::stack<int> foo; // .. for (__typeof(foo.begin()) it = foo.begin(); it != foo.end(); it++) { // ... } Is it possible to traverse std::stack in C++? No. A stack is a data structure you should use when you are interested in placing elements on top and getting elements from the top. If you want an iterable stack, either use a different data structure for a stack role ( std::vector ?) or write one yourself. Rahul Tripathi I don't think that it is possible to

What maximum size of static arrays are allowed in C?

笑着哭i 提交于 2019-12-05 06:38:56
In my algorithm I know work with static arrays, no dynamic ones. But I sometimes reach the limit of the stack. Am I right, that static arrays are stored to the stack? Which parameters affect my maximum stack size for one C programm? Are there many system parameters which affect the maximal array size? Does the maximunm no. of elements depend of the array type? Does it depend on the total system RAM? Or does every C programm have a static maximum stack size? Most of your questions have been answered, but just to give an answer that made my life a lot easier: Qualitatively the maximum size of

PHP Stack Implementation

寵の児 提交于 2019-12-05 06:22:53
I want to construct a stack implemented in PHP. Initially I have this code: class Stack { protected $stack; protected $limit; public function __construct($limit = 10) { // initialize the stack $this->stack = array(); // stack can only contain this many items $this->limit = $limit; } public function push($item) { // trap for stack overflow if (count($this->stack) < $this->limit) { // prepend item to the start of the array array_unshift($this->stack, $item); } else { throw new RunTimeException('Stack is full!'); } } public function pop() { if ($this->isEmpty()) { // trap for stack underflow

What is the “standard” size of the stack and the heap in a C program?

☆樱花仙子☆ 提交于 2019-12-05 06:09:25
I have read that the "standard" and initial stack size on Linux is ~8MB and Windows is ~1MB. But how does the heap allocation work? Does the OS set a "virtual" size to the process heap like it does for the stack with committed and reserved memory? Classically, the layout of a program has the 'text' (or 'code') segment at the low end of memory, followed by the fixed data ('data' and 'bss' segments), followed by a gap, with the stack growing downwards from high memory. The gap in the middle becomes the heap, which grows from the end of the data towards the stack. Things are more complex with

determine stack depth in javascript using javascript

不问归期 提交于 2019-12-05 05:34:46
Is there a way to determine the stack depth of all functions being executed in javascript by using javascript itself? I'm thinking it might involve modifying the Function prototype, but I really don't have any idea. Additionally, it would be nice to be able to break anytime the stack depth were sufficiently high. The reason for this is that I have a stack overflow error in IE which is apparently not debuggable . I'm lazy and I would rather not have to hunt through the code that I'm maintaining to find the cause. Thanks for assisting my laziness. ECMAscript supported for quite a while the

Local variables on stack

杀马特。学长 韩版系。学妹 提交于 2019-12-05 05:25:59
问题 To understand the stack frame concept, I wrote a little program for my own. First I will show you the code, a little sketch about it and then I will present my question: So, the program: int check_pw(char *password){ int valid = 0; char buffer[10]; strcpy(buffer, password); if(strcmp(buffer, "a") == 0){ valid = 1; } return valid; } int main(int argc, char *argv[]){ if(check_pw(argv[1])){ printf("OK\n"); } else{ printf("Wrong password\n"); } } I give the password as a command-line argument.

Modify return address on stack

我的梦境 提交于 2019-12-05 05:21:19
I looked at the basics of buffer overflow vulnerabilities and tried to understand how the stack is working. For that I wanted to write a simple program which changes the address of the return address to some value. Can anybody help me with figuring out the size of the base pointer to get the offset from the first argument? void foo(void) { char ret; char *ptr; ptr = &ret; //add some offset value here *ptr = 0x00; } int main(int argc, char **argv) { foo(); return 1; } The generated assembler code looks as follows: .file "test.c" .text .globl foo .type foo, @function foo: .LFB0: .cfi_startproc

The C++ implicit this, and exactly how it is pushed on the stack

随声附和 提交于 2019-12-05 05:09:12
I need to know whether, when a class method in C++ is called, the implicit 'this' pointer is the first argument, or the last. i.e: whether it is pushed onto the stack first or last. In other words, I'm asking whether a class method, being called, is taken by the compiler to be: int foo::bar(foo *const this, int arg1, int arg2); //or: int foo::bar(int arg1, int arg2, foo *const this); By extension therefore, and more importantly, that would also answer whether G++ would push the this pointer last or first, respectively. I interrogated google, but I didn't find much. And as a side note, when C++

Is there a maximum limit to the size of a variable that should be allocated on a stack?

六月ゝ 毕业季﹏ 提交于 2019-12-05 03:59:47
i declared a struct variable in C of size greater than 1024bytes. On running Coverity (a static code analyzer application) it reports that this stack variable is greater than 1024 bytes and therefore a cause of error. I'd like to know if I need to worry about this warning? Is there really a maximum limit to the size of a single stack variable? thanks, che The maximum size of a variable is the limited by the maximum size of the stack (specifically, how much of the stack is left over from any current use including variables and parameters from functions higher on the stack as well as process

Convert from an infix expression to postfix (C++) using Stacks

那年仲夏 提交于 2019-12-05 03:15:24
My lecturer gave me an assignment to create a program to convert and infix expression to postfix using Stacks. I've made the stack classes and some functions to read the infix expression. But this one function, called convertToPostfix(char * const inFix, char * const postFix) which is responsible to convert the inFix expression in the array inFix to the post fix expression in the array postFix using stacks, is not doing what it suppose to do. Can you guys help me out and tell me what I'm doing wrong? The following is code where the functions to convert from inFix to postFix is and