The following code snippet:
void (*foo)(); char X[1]; char Y[10];
could intuitively give me one possible alignment:
| Y[10] | |---------| | X[1] | |---------| | foo | |---------|
I studied this by creating an ASM file using:
gcc -S -o stack stack.c
Then I realized that the order in which these variables are pressed is different. So, if I accidentally did X[1], I expected to refer to Y[0], but in the actual layout, writing something in X[1]overwrites the first byte of the memory cell allocated for foo. Is reorganization a compiler optimization step or can someone tell me why this is happening?
X[1]
Y[0]
foo
Why do you say "need"?
, - , , .
, "".
, ( , !) , struct #pragma s.
struct
#pragma
, . , , , . , , , , .
, , , - , . , . , , , , . , , , .
-, . :
push A push B
A , B, B ( A). C:
int stk[BIG]; int stk_top = BIG;
void stk_push(int x) { stk_top--; stk[stk_top] = x; }
, stk_top , .
- , , . , , , . , . , , , . , . , . , , , .
: char , .
char
, "" , . , 32- int 32- . , "" , .
int
, , .
| var | address | |---------|---------| | Y[10] | x | |---------|---------| | X[1] | x + 10 | |---------|---------| | foo | x + 11 | |---------|---------|
, , ( ), , , . , X[1] = *(x + 10 + 1) = foo
X[1] = *(x + 10 + 1) = foo
, .
, ? 4- . ?
char x[11]; char *y = &x[1];
Source: https://habr.com/ru/post/1770566/More articles:Sending ctrl + z to the console program - cSQL Server 2005: временная метка T-SQL INSERT INTO и OUTPUT для переменной - sqlSignal Scan - c ++Does the web browser fulfill the "xmlns" attribute? - browserSync'd Hashtable does not support PowerShell. Try: [HashTable] :: Synchronized (@ {}) - hashtablehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1770567/c-based-windows-service-tries-to-do-jit-debugging-in-production&usg=ALkJrhgSnaVxMKL_trQOMIH1oJmz6Zx_nwUsing watir to manage multiple instances of firefox - firefoxCalling a base method from a derived class - c ++Tomcat / admin applications for several $ CATALINA_BASES - javaIs Object the preferred Associative container in AS3? - flexAll Articles