stack

Is using alloca() for variable length arrays better than using a vector on the heap?

假如想象 提交于 2019-12-06 12:47:45
I have some code using a variable length array (VLA), which compiles fine in gcc and clang, but does not work with MSVC 2015. class Test { public: Test() { P = 5; } void somemethod() { int array[P]; // do something with the array } private: int P; } There seem to be two solutions in the code: using alloca() , taking the risks of alloca in account by making absolutely sure not to access elements outside of the array. using a vector member variable (assuming that the overhead between vector and c array is not the limiting factor as long as P is constant after construction of the object) The

Lisp expression evaluator in Java (using only one stack)

拟墨画扇 提交于 2019-12-06 12:16:23
问题 I'm trying to implement a simple Lisp expression evaluator using Java. There's actually a wealth of information on the subject, but it appears they all use two separate stacks to arrive at the result. I'm wondering if it is possible to implement such a program using only one stack and what some pseudo code might look like for that. Thanks. For more info on what I'm talking about refer to http://www.chegg.com/homework-help/questions-and-answers/outline-given-import-javautil-public-class

Clear backstack in Android pre Honeycomb?

老子叫甜甜 提交于 2019-12-06 12:00:21
Is there an easy way or another workaround to delete the backstack in Android pre Honeycomb(before API level 11)? People suggest using the FLAG_ACTIVITY_CLEAR_TOP in conjunction with FLAG_ACTIVITY_NEW_TASK when starting a new activity, but this does only delete the stack on top of my current position, not the stack under my position. It should not be that hard to start from a fresh task. Some ideas around this? I can not use FLAG_ACTIVITY_CLEAR_TASK because I need to support those versions beneath api level 11. Is there an equivalent to FLAG_ACTIVITY_CLEAR_TASK that clears the whole navigation

what exactly is program stack's growth direction?

梦想与她 提交于 2019-12-06 11:58:06
问题 I'm reading Professional Assembly Language by Richard Blum,and I am confusing about a Inconsistency in the book and I wondering what exactly is program stack's growth direction? This is the picture from page 312, which is suggesting that program stack grows up. But when I reached page 322,I see another version, which suggesting that program stack grows down. and this 回答1: The book is not inconsistent; each drawing shows higher addresses at the top. The first drawing illustrates a stack that

Add missing left parentheses into equation [closed]

北城以北 提交于 2019-12-06 11:03:42
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm pretty stuck in finding a proper solution for a given problem, been looking for some ideas over the internet. Wasn't be able to find any. Problem is: writing a program that takes from the standard input an expression without left parentheses and prints the equivalent infix expression with the parentheses inserted. Given expression: 1 + 2) * 3 - 4)* 5 - 6))) Output: ((1 + 2) * ((3 - 4) * (5 - 6))) What can be

NSLog(…) improper format specifier affects other variables?

﹥>﹥吖頭↗ 提交于 2019-12-06 09:42:59
I recently wasted about half an hour tracking down this odd behavior in NSLog(...): NSString *text = @"abc"; long long num = 123; NSLog(@"num=%lld, text=%@",num,text); //(A) NSLog(@"num=%d, text=%@",num,text); //(B) Line (A) prints the expected "num=123, text=abc", but line (B) prints "num=123, text= (null) ". Obviously, printing a long long with %d is a mistake, but can someone explain why it would cause text to be printed as null? You just messed up memory alignment on your stack. I assume than you use newest Apple product with x86 processor. Taking these assumptions into account your stack

Should a list of objects be stored on the heap or stack?

烂漫一生 提交于 2019-12-06 08:34:52
问题 I have an object(A) which has a list composed of objects (B). The objects in the list(B) are pointers, but should the list itself be a pointer? I'm migrating from Java to C++ and still haven't gotten fully accustomed to the stack/heap. The list will not be passed outside of class A, only the elements in the list. Is it good practice to allocate the list itself on the heap just in case? Also, should the class that contains the list(A) also be on the heap itself? Like the list, it will not be

runtime: goroutine stack exceeds 1000000000-byte limit, fatal error: stack overflow on printing a nested struct

寵の児 提交于 2019-12-06 08:22:01
问题 I have a nested struct. type ConfigOne struct { // Daemon section from config file. Daemon daemon } type daemon struct { Loglevel int Logfile string } And I have a String() string method on that type, which I am trying to return the nested struct elements as func (c ConfigOne)String() string{ return fmt.Sprintf("%+v\n", c) } When I am trying to print it as c := &modules.ConfigOne{} c.Daemon.Loglevel = 1 c.Daemon.Logfile = "/tmp/test.log" modules.Logger.Infoln(c.String()) I am getting the

Convert Infix to Postfix with Stack [duplicate]

白昼怎懂夜的黑 提交于 2019-12-06 08:09:56
问题 This question already has answers here : Handling parenthesis while converting infix expressions to postfix expressions (2 answers) Closed 2 years ago . I have to make a program that changes an expression written in Infix notation to Postfix notation. I am running into a problem when I start using parentheses. For example, when I put in "a + (c - h) / (b * d)" is comes out as "ac+h-b/d*" when it should come out as "a c h - b d * / +." Would really appreciate the help. Thanks. import java.util

Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted

房东的猫 提交于 2019-12-06 07:24:04
问题 I receive this Run-Time Check Failure upon the return in the following code. I believe similar code is running fine elsewhere in the program. Any ideas? String GetVariableName(CString symbol, CString filepath) { char acLine[512]; char acPreviousLine[512]; CString csFile; FILE *fp; csFile.Format("%svariables.txt", filepath); fp = fopen(csFile, "r"); if (! fp) return(""); for (;;) { strcpy(acPreviousLine, acLine); // NULL means we are out of lines in the file. if (myfgets(acLine, 511, fp) ==