stack

How does gcc push local variables on to the stack?

送分小仙女□ 提交于 2021-02-19 08:54:30
问题 void f () { int a[1]; int b; int c; int d[1]; } I have found that these local variables, for this example, are not pushed on to the stack in order. b and c are pushed in the order of their declaration, but, a and d are grouped together. So the compiler is allocating arrays differently from any other built in type or object. Is this a C/C++ requirement or gcc implementation detail? 回答1: The C standard says nothing about the order in which local variables are allocated. It doesn't even use the

How do I find largest valid sequence of parentheses and brackets in a string?

笑着哭i 提交于 2021-02-18 12:47:15
问题 So I have a script I need to write and one of the largest problems boils down to finding the largest valid subsequence within a string. So I have something like "()(({}[](][{[()]}]{})))(" as an input and I would need to return "[{[()]}]{}" as an output. I have tried using a stack like structure like you would do if it was just parentheses but haven't been able to figure out something that works. I'd prefer a solution in python but any guidance anyone can offer will help regardless of language

Loop within STACK question in moodle using jsxgraph

旧巷老猫 提交于 2021-02-11 12:36:28
问题 I am trying to create a moodle-STACK question with an interactive element via jsxgraph . Within the [[jsxgraph]] ... [[/jsxgraph]] tags, I am plotting a curve with two databases, each with 6 elements. Since I would like students to add error bars for both scales, I added a loop within the jsxgraph-element : var plot = function() { var j, xr0, yr0, xr1, yr1, xr2, yr2, err1, err2; board.suspendUpdate(); for (j=0; j<6;j++) { const v1 = Number(input1.Value()); const v2 = Number(input2.Value());

How to extract information from Java stack as individual data types and use in method call

点点圈 提交于 2021-02-10 18:17:53
问题 I am trying to implement an undo feature by creating a stack of 2 subtypes. I have a stack of parent type UserEntry holding two child types Assign and RelEntry. Assign and RelEntry is both classes used to insert values (number and relationship) into a grid table. There is a method call to insert the values into the table as their respective subtypes for example assignToTable() and RelEntryToTable() . I am trying to use a polymorphic method that can call both of these subtypes from the parent

Printf arguments not pushed on the stack

蹲街弑〆低调 提交于 2021-02-10 13:15:26
问题 I'm in the process of trying to understand the stack mechanisms. From the theory I have seen, before a function is called, its arguments are pushed onto the stack. However when calling printf in the code below, none of them are pushed: #include<stdio.h> int main(){ char *s = " test string"; printf("Print this: %s and this %s \n", s, s); return 1; } I've put a break in gdb to the printf instruction, and when displaying the stack, none of the 3 arguments are pushed onto the stack. The only

Printf arguments not pushed on the stack

筅森魡賤 提交于 2021-02-10 13:11:26
问题 I'm in the process of trying to understand the stack mechanisms. From the theory I have seen, before a function is called, its arguments are pushed onto the stack. However when calling printf in the code below, none of them are pushed: #include<stdio.h> int main(){ char *s = " test string"; printf("Print this: %s and this %s \n", s, s); return 1; } I've put a break in gdb to the printf instruction, and when displaying the stack, none of the 3 arguments are pushed onto the stack. The only

Printf arguments not pushed on the stack

放肆的年华 提交于 2021-02-10 13:09:03
问题 I'm in the process of trying to understand the stack mechanisms. From the theory I have seen, before a function is called, its arguments are pushed onto the stack. However when calling printf in the code below, none of them are pushed: #include<stdio.h> int main(){ char *s = " test string"; printf("Print this: %s and this %s \n", s, s); return 1; } I've put a break in gdb to the printf instruction, and when displaying the stack, none of the 3 arguments are pushed onto the stack. The only

Member function memory allocation stack or heap?

那年仲夏 提交于 2021-02-10 12:57:23
问题 I'm trying to allocate an array as follows: class foo{ public: void func(){double arr[13][64][64][64];} }; int main() { foo* inst = new foo(); inst->func(); return 0; } I was under the impression from answer such as: Does this type of memory get allocated on the heap or the stack? that the array arr would be placed on the heap (as the instance of the class is on the heap). This doesn't seem to be the case as I get a segmentation fault. If I change a's declaration to: double* arr = new double

Member function memory allocation stack or heap?

こ雲淡風輕ζ 提交于 2021-02-10 12:56:24
问题 I'm trying to allocate an array as follows: class foo{ public: void func(){double arr[13][64][64][64];} }; int main() { foo* inst = new foo(); inst->func(); return 0; } I was under the impression from answer such as: Does this type of memory get allocated on the heap or the stack? that the array arr would be placed on the heap (as the instance of the class is on the heap). This doesn't seem to be the case as I get a segmentation fault. If I change a's declaration to: double* arr = new double

stack implementation using malloc in c [BEGINNER]

て烟熏妆下的殇ゞ 提交于 2021-02-07 19:47:18
问题 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