История изменений
Исправление user_id_68054, (текущая версия) :
оставлю это тут:
[regular-user@localhost Desktop]$ cat x.cpp
#include <stdio.h>
#include <string.h>
typedef struct {
char text[256];
int type;
} Token;
Token tok_get() {
Token t_tok;
printf("Pointer in function tok_get %lx\n", &t_tok);
return t_tok;
}
int main(void) {
//Token t_main;
//printf("Pointer in function main %lx\n", &t_main);
//t_main = tok_get();
Token t_main = tok_get(); // теперь попробуем вот так
printf("Pointer after assign %lx\n", &t_main);
return 0;
}
[regular-user@localhost Desktop]$ gcc -o x x.cpp # ни какой оптимизации
[regular-user@localhost Desktop]$ ./x
Pointer in function tok_get 7fff78ffbd70
Pointer after assign 7fff78ffbd70
[regular-user@localhost Desktop]$ mv -v x.cpp x.c
‘x.cpp’ -> ‘x.c’
[regular-user@localhost Desktop]$ gcc -o x x.c
[regular-user@localhost Desktop]$ ./x
Pointer in function tok_get 7fff87c71ad0
Pointer after assign 7fff87c71bf0
Исходная версия user_id_68054, :
оставлю это тут:
[regular-user@localhost Desktop]$ cat x.cpp
#include <stdio.h>
#include <string.h>
typedef struct {
char text[256];
int type;
} Token;
Token tok_get() {
Token t_tok;
printf("Pointer in function tok_get %lx\n", &t_tok);
return t_tok;
}
int main(void) {
//Token t_main;
//printf("Pointer in function main %lx\n", &t_main);
//t_main = tok_get();
Token t_main = tok_get(); // теперь попробуем вот так
printf("Pointer after assign %lx\n", &t_main);
return 0;
}
[regular-user@localhost Desktop]$ gcc -o x x.cpp # ни какой оптимизации
[regular-user@localhost Desktop]$ ./x
Pointer in function tok_get 7fff78ffbd70
Pointer after assign 7fff78ffbd70