struct S
{
int * a;
int * b;
};
#include <stdio.h>
#include "struct.h"
struct S f (struct S v)
{
printf ("va =% d, vb =% d \ n", * va, * vb);
return v;
}
#include <stdio.h>
#include "struct.h"
int main ()
{
int a = 1, b = 2;
struct S v = {& a, & b};
f (v);
printf ("a =% d, b =% d \ n", a, b);
return 0;
}
all: test
./test
test: ac bc struct.h
gcc ac bc -g -o test
va = 2, vb = 0 a = 8559808, b = -2398008
Position After Call After Returning Position
4n + 4 (% esp) | word n ​​| | word n ​​| 4n-4 (% esp)
| ... | | | ... | |
8 (% esp) | word 1 | | word 1 | 0 (% esp)
| ------------ | | -------------- |
4 (% esp) | address | | not defined |
| result | | |
| ------------ | | |
0 (% esp) | address | | |
| return | | |
| ------------ | | -------------- |
Calling Immediately
function function after return
(expected)
16 (% esp) | local | | | | local |
| | | ------------ | | |
12 (% esp) | variables | | vb | | variables |
| ============ | | | | -------------- |
8 (% esp) | vb | | va | | vb | 0 (% esp)
| ------------ | | ------------ | | ============== |
4 (% esp) | va | | address | | not defined |
| | | result | | |
| ============ | | ------------ | | |
0 (% esp) | address | | address | | |
| return | | return | | |
| ------------ | | ------------ | | -------------- |
Source: https://habr.com/ru/post/95930/
All Articles