stack

stack implementation using malloc in c [BEGINNER]

a 夏天 提交于 2021-02-07 19:46:39
问题 for learning purpose I'm implementing a stack with it's functions in c. I added some small additional functionality to use malloc the first time and try to understand it properly. I wrote a function which is initially creating my stack struct. The return value of the function is a new struct with an already allocate memory. What is the best way to handle a malloc exception in a function which return value should be a struct? Maybe should I design the function different? I'm aware that the

Converting from Infix to Postfix and evaluating Postfix notation

戏子无情 提交于 2021-02-07 11:13:50
问题 I'm writing a program that reads an Infix notation, converts it to Postfix and then evaluate that Postfix. Here's my program: #include<stdio.h> #include <ctype.h> #define SIZE 50 /* Size of Stack */ char s[SIZE]; int top = -1; /* Global declarations */ push(char elem) { /* Function for PUSH operation */ s[++top] = elem; } char pop() { /* Function for POP operation */ return (s[top--]); } int pr(char elem) { /* Function for precedence */ switch (elem) { case '#': return 0; case '(': return 1;

Converting from Infix to Postfix and evaluating Postfix notation

只谈情不闲聊 提交于 2021-02-07 11:13:45
问题 I'm writing a program that reads an Infix notation, converts it to Postfix and then evaluate that Postfix. Here's my program: #include<stdio.h> #include <ctype.h> #define SIZE 50 /* Size of Stack */ char s[SIZE]; int top = -1; /* Global declarations */ push(char elem) { /* Function for PUSH operation */ s[++top] = elem; } char pop() { /* Function for POP operation */ return (s[top--]); } int pr(char elem) { /* Function for precedence */ switch (elem) { case '#': return 0; case '(': return 1;

How to check stack and heap usage with C on Linux?

落花浮王杯 提交于 2021-02-07 08:02:34
问题 Is there any way to retrieve the stack and heap usage in C on Linux? I want to know the amount of memory taken specifically by stack/heap. 回答1: If you know the pid (e.g. 1234) of the process, you could use the pmap 1234 command, which print the memory map. You can also read the /proc/1234/maps file (actually, a textual pseudo-file because it does not exist on disk; its content is lazily synthesized by the kernel). Read proc(5) man page. It is Linux specific, but inspired by /proc file systems

Does each thread have its own stack?

余生颓废 提交于 2021-02-05 21:38:32
问题 When I create multiple threads from a process, then does each thread have its own stack, or is it that they share the stack of their parent process. What happens when a thread makes a system call? Do threads also maintain their own kernel stack like processes? 回答1: Yes threads have their own stacks and their own kernel stacks (e.g. linux). When a thread makes a system call, you trap into kernel mode (from user mode), you pass the arguments to the kernel, the arguments are checked, the kernel

Does each thread have its own stack?

断了今生、忘了曾经 提交于 2021-02-05 21:35:33
问题 When I create multiple threads from a process, then does each thread have its own stack, or is it that they share the stack of their parent process. What happens when a thread makes a system call? Do threads also maintain their own kernel stack like processes? 回答1: Yes threads have their own stacks and their own kernel stacks (e.g. linux). When a thread makes a system call, you trap into kernel mode (from user mode), you pass the arguments to the kernel, the arguments are checked, the kernel

SPOJ - Runtime error SIGSEGV

谁说我不能喝 提交于 2021-02-05 08:33:22
问题 Following is the implementation of infix to postfix conversion, it is working fine on my computer, but as I am submitting in on SPOJ it is giving me Runtime error SIGSEGV , I am new to competitive programming and I am unable to handle such type of errors. #include <iostream> #include <stack> #include<string.h> #include<ctype.h> using namespace std; int prec(char ch){ switch(ch){ case '^' : return 3; break; case '*': case '/': return 2; break; case '+': case '-': return 1; break; default:

Would having the call stack grow upward make buffer overruns safer?

亡梦爱人 提交于 2021-02-05 04:56:16
问题 Each thread has its own stack to store local variables. But stacks are also used to store return addresses when calling a function. In x86 assembly, esp points to the most-recently allocated end of the stack. Today, most CPUs have stack grow negatively. This behavior enables arbitrary code execution by overflowing the buffer and overwriting the saved return address. If the stack was to grow positively, such attacks would not be feasible. Is it safer to have the call stack grow upwards? Why

Would having the call stack grow upward make buffer overruns safer?

情到浓时终转凉″ 提交于 2021-02-05 04:54:06
问题 Each thread has its own stack to store local variables. But stacks are also used to store return addresses when calling a function. In x86 assembly, esp points to the most-recently allocated end of the stack. Today, most CPUs have stack grow negatively. This behavior enables arbitrary code execution by overflowing the buffer and overwriting the saved return address. If the stack was to grow positively, such attacks would not be feasible. Is it safer to have the call stack grow upwards? Why

Would having the call stack grow upward make buffer overruns safer?

瘦欲@ 提交于 2021-02-05 04:53:32
问题 Each thread has its own stack to store local variables. But stacks are also used to store return addresses when calling a function. In x86 assembly, esp points to the most-recently allocated end of the stack. Today, most CPUs have stack grow negatively. This behavior enables arbitrary code execution by overflowing the buffer and overwriting the saved return address. If the stack was to grow positively, such attacks would not be feasible. Is it safer to have the call stack grow upwards? Why