stack

Does the C language specify a stack? [duplicate]

余生颓废 提交于 2020-01-16 17:36:15
问题 This question already has answers here : Size of stack and heap memory [duplicate] (4 answers) What and where are the stack and heap? (25 answers) Does C need a stack and a heap in order to run? (3 answers) Closed last year . Does the C language definition require the existence of a stack? What about architectures that don't support stacks? Does that mean that such architectures can't implement the C language as it is defined? What about the heap? 回答1: No. The C11 standard does not contain

Returning string from a C function [duplicate]

点点圈 提交于 2020-01-16 04:52:09
问题 This question already has answers here : returning a pointer to a literal (or constant) character array (string)? (3 answers) Closed 3 years ago . I have a simple code. #define MY_STRING "String example" char* string_return_function() { return MY_STRING; } The above code works but I am not sure how. I think the string_return_function() returns a local address, which would gets freed once the function exits. 回答1: No, that's not how it works. String literals are stored in memory that persists

Doesn't the frame pointer make the stack pointer redundant?

£可爱£侵袭症+ 提交于 2020-01-16 03:56:36
问题 As far as I understand it, the stack pointer points to the "free" memory on the stack, and "pushing" data on the stack writes to the location pointed by the stack pointer and increments/decrements it. But isn't it possible to use offsets from the frame pointer to achieve the same thing, thus saving a register. The overhead from adding offsets to the frame pointer is pretty much the same as the overhead of incrementing and decrementing the stack pointer. The only advantage I see is accessing

how to make my stack class dynamic

笑着哭i 提交于 2020-01-15 03:18:27
问题 i write a stack class in c++ (shown below) but it is static and sure it uses lots of memory's. how can i make it dynamic so when ever it need it add some memory to the object and when ever i pop something the memory automatically delete? template <class T> class stack { private: T value[512]; uint16_t length; public: stack() { length=0; } stack(T _input) { value[0]=_input; length=1; } bool push(T _input) { if(length+1<512) { value[++length]=_input; return true; } else return false; } T pop()

Bluecove : restart bluetooth stack programmatically

时光怂恿深爱的人放手 提交于 2020-01-14 19:30:50
问题 I'm trying to close bluetooth service, but Bluecove has bug on Connection close method (https://code.google.com/p/bluecove/issues/detail?id=90) and I am trying to do some workaround to restart service. I think restarting bluetooth stack will solve my problem. Can I do it programmatically? I'am using microsoft bluetooth stack. 回答1: Problem solved in this way. I restart the application, but firstly shut down bluecove manually. BlueCoveImpl.shutdown(); If I only restart application, bluecove

Is there a upper limit on stack frame size

倖福魔咒の 提交于 2020-01-14 13:36:45
问题 We have an out of memory error for a heap but ( just asking out of curiosity ) is there an equivalent limit on size of an individual stack ? If not then what prevents such an overflow if excess memory is needed by a stack frame ( like thousands of local variable etc ) ? 回答1: If a thread requests more stack space than it has available it receives a StackOverflowError. http://docs.oracle.com/javase/7/docs/api/java/lang/StackOverflowError.html The size of an individual stack frame is determined

Is there a upper limit on stack frame size

荒凉一梦 提交于 2020-01-14 13:36:31
问题 We have an out of memory error for a heap but ( just asking out of curiosity ) is there an equivalent limit on size of an individual stack ? If not then what prevents such an overflow if excess memory is needed by a stack frame ( like thousands of local variable etc ) ? 回答1: If a thread requests more stack space than it has available it receives a StackOverflowError. http://docs.oracle.com/javase/7/docs/api/java/lang/StackOverflowError.html The size of an individual stack frame is determined

Infix to postfix conversion in java

匆匆过客 提交于 2020-01-13 18:15:46
问题 I have a java class that converts infix expression to postfix. I have managed to make the class run without errors but it is not giving me the right output. The output is suppose to be in form : InToPost: converting expressions from infix to postfix... [A, +, B] [A, +, B, *, C] [A, +, B, *, C, +, D] [(, A, +, B, ), *, C] [(, A, +, B, ), /, (, C, -, D, )] [(, (, A, +, B, ), *, C, -, (, D, -, E, ), )] InToPost: emitting postfix expressions... A B + A B C * + A B C * + D + A B + C * A B + C D -

Infix to postfix conversion in java

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 18:15:29
问题 I have a java class that converts infix expression to postfix. I have managed to make the class run without errors but it is not giving me the right output. The output is suppose to be in form : InToPost: converting expressions from infix to postfix... [A, +, B] [A, +, B, *, C] [A, +, B, *, C, +, D] [(, A, +, B, ), *, C] [(, A, +, B, ), /, (, C, -, D, )] [(, (, A, +, B, ), *, C, -, (, D, -, E, ), )] InToPost: emitting postfix expressions... A B + A B C * + A B C * + D + A B + C * A B + C D -

declare fixed size character array on stack c++

风流意气都作罢 提交于 2020-01-13 11:43:33
问题 I am attempting to create a character array of a fixed size on the stack (it does need to be stack allocated). the problem I am having is I cannot get the stack to allocate more than 8 bytes to the array: #include <iostream> using namespace std; int main(){ char* str = new char[50]; cout << sizeof(str) << endl; return 0; } prints 8 How do I allocate a fixed size array (in this case 50 bytes. but it may be any number) on the stack? 回答1: char* str = new char[50]; cout << sizeof(str) << endl; It