我正在尝试编译我的程序并使其可执行,但每次我尝试打印时都说:“当前上下文中没有符号”郁金香“。 “
这是我的代码:
#include <stdlib.h>
#include <stdio.h>
int main() {
unsigned long *daffodil = (unsigned long *) malloc(sizeof(unsigned long));
if (daffodil == (unsigned long *) NULL)
exit(EXIT_FAILURE);
*daffodil = 170;
unsigned long *tulip = daffodil;
unsigned long *carnation = (unsigned long *) malloc(sizeof(unsigned long));
if (carnation == (unsigned long *) NULL)
exit(EXIT_FAILURE);
*carnation = 995;
unsigned long *lily = tulip;
unsigned long crocus = 953;
unsigned long *zinnia = &crocus;
(void) printf("Registering daffodil: %lu.\n", *daffodil);
(void) printf("Registering tulip: %lu.\n", *tulip);
(void) printf("Registering carnation: %lu.\n",*carnation);
(void) printf("Registering lily: %lu.\n", *lily);
(void) printf("Registering crocus: %lu.\n", crocus);
(void) printf("Registering zinnia: %lu.\n", *zinnia);
carnation = (unsigned long *) NULL;
free(daffodil);
free(carnation);
return EXIT_SUCCESS;
}
答案 0 :(得分:2)
为了在GDB中查看局部变量,你必须打破该函数内的程序执行。您试图在程序终止后打印该值,这是不可能的。
尝试在第10行设置一个断点,我想:
FORMULA1- COLL_DATE
if Collection_Rejection_Desc = 'Cleared'
then Coll_Rej_Dt
else null
FORMULA2- REJ_DATE
if Collection_Rejection_Desc = 'Rejected'
then Coll_Rej_Dt
else null
您也可以在(gdb) br 10
(gdb) run
(gdb) print tulip
的开头处中断,然后前进直到变量初始化为止:
main
(gdb) br main
(gdb) run
(gdb) next
(gdb) next
(gdb) ...
(gdb) print tulip
处的断点非常频繁,main
有一个自动执行此操作的命令:gdb
。
如果您对变量特别感兴趣,那么您可以显示它,以便在每一步都自动打印:
start