stack

How will you find out if a stack grows up or down in a system? [duplicate]

依然范特西╮ 提交于 2019-12-25 01:23:55
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: stack growth direction Does stack grow upward or downward? Hi all, How would I find out if a machine’s stack grows up or down in memory in C. More importantly, which is better: a system in which the stack grows up or one in which a stack grows down ? And will below logic work ??? void sub(int *a) { int b; if (&b > a) { printf("Stack grows up."); } else { printf("Stack grows down."); } } main () { int a; sub(&a)

how do the registers get saved when a process gets interrupted?

前提是你 提交于 2019-12-25 01:13:33
问题 this has been bugging me all day. When a program sets itself up to call a function when it receives a certain interrupt, I know that the registers are pushed onto the stack when the program is interrupted, but what I can't figure out is: how do the registers get off the stack? I know that the compiler doesn't know if the function is an interrupt handler, and it can't know how many arguments the interrupt gave to the function. So how on earth does it get the registers off? 回答1: It depends on

memcpy overflow boundary exploit? (smashing the stack)

大城市里の小女人 提交于 2019-12-25 00:44:26
问题 I'm trying to figure out if this could somehow be overflowed: void print_address(char *p) { arp_ hw; int i; hw.length = (size) *(p + _OFFSET1); //189 + 4 = 193 memcpy(hw.addr, packet + _OFFSET2, hw.length); return; } where packet is an input read from a .txt file? 回答1: hwaddr.len is an unsigned char which has range 0 to 255. So an attacker could send you a packet which declares length 255. Since hwaddr.addr is declared as a 128-byte buffer, the attacker can then deliver a payload of 127 bytes

flutter - Anyone know how to create photo with stack silverlist?

∥☆過路亽.° 提交于 2019-12-24 20:25:41
问题 I want to create a profile photo with a stack, below it is a silver list (for animation purposes when scroll) How do I add the stack photo next to the silverlist, then when the discroll down the photo shrinks, if scroll back to the top, the photo enlarges as before. see the comparison of the image below: Widget _buildDetailFood(BuildContext context) { return CustomScrollView( slivers: <Widget>[ SliverAppBar( pinned: true, floating: false, expandedHeight: 256, flexibleSpace: FlexibleSpaceBar(

Why do we need to create an object in heap?

梦想的初衷 提交于 2019-12-24 19:34:07
问题 why can we use the stack for all our needs? NOTE: it will be very good if you give an example while explaining because it is easier to understand with examples. sorry for bad English. 回答1: In practice the call stack is limited and small. The typical limit is a few megabytes. In contrast, you could often allocate gigabytes in heap memory. (on some systems, you might configure the system to have a larger stack; but you need to tell your users if you need that) Also, and most importantly, the

Should I make stack segment large or heap segment large?

耗尽温柔 提交于 2019-12-24 17:35:11
问题 I'm programming a design for a microprocessor with very limited memory and I must use "a lot" of memory in different functions. I can't have a large stack segment, heap segment, data segment, I must choose which to make big and which to make small. I have about 32KB total, I use about 20KB for the text segment, that gives me 12KB for the rest. And I need a buffer of 4KB to pass to different functions (SPI Flash sector size). Where should initialize that large buffer? So my choices are: 1) If

C stack usage with temporary structures

半腔热情 提交于 2019-12-24 16:52:30
问题 I work with embedded stuff, so, I use special C compiler C30 for MCUs. I'm confused about its behavior with temporary structures. But, maybe I don't know something, and it's intended behavior? Consider little code: typedef struct { int a; int b; } T_TestStruct1; void test1(T_TestStruct1 *p_test_struct) { /* do something */ } And these calls to test1() : void some_function() { { T_TestStruct1 par = { .a = 1, .b = 1, }; test1(&par); } { T_TestStruct1 par = { .a = 2, .b = 2, }; test1(&par); } }

Understanding Stack implementation problem statement

谁说我不能喝 提交于 2019-12-24 13:49:52
问题 I need to compute the peek mid element also the problem statement for implementing this method is as follows:- *returns object which has the middle value among the all objects without removing it from the stack. *returns the object which has the value of following order (size()/2)+1 *e.g. *When the stack has the following values (1, 2, 5, 4, 2, 6) *this method returns 4 and doesn't remove the object. so my query is:- should i consider the middle element in terms of position i.e. after sorting

How to Pop different types of Structs from a Stack

余生长醉 提交于 2019-12-24 12:34:39
问题 I have a stack that contains two types of struct. Struct Stud and Struct Prof. When I want to push something I created two Push functions for both structs. Although I would like it to be with one function but its ok I can bear with it. Now to Pop. If I want to Pop a student from the Stack, do I have to make a Pop function specifically for Students only? The same with Professors? How can I store the item if I don't know what type is it? What type must the element be, to store the item there?

c++ while loop doesn't exit on false condition [closed]

时间秒杀一切 提交于 2019-12-24 11:14:19
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I'm having a problem in my code that results in a run time error. To debug the code I've thrown in some cout statements to find the last location that