#include<stdio.h>
int main(int argc,char *argv[])
{
int i=10;
void *k;
k=&i;
k++;
printf("%p\n%p\n",&i,k);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
++是对void*的合法操作吗?有些书说它不是,但K&R没有说任何关于void*算术的内容(K&R 2/e的第93,103,120,199页)
请澄清.
PS:GCC至少在k ++中没有抱怨.
$ gcc -O2 -S test.c -----------------------(1)
.file "test.c"
.globl accum
.bss
.align 4
.type accum, @object
.size accum, 4
accum:
.zero 4
.text
.p2align 2,,3
.globl sum
.type sum, @function
sum:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
addl 8(%ebp), %eax
addl %eax, accum
leave
ret
.size sum, .-sum
.p2align 2,,3
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
subl $16, %esp
pushl $11
pushl $10
call sum
xorl %eax, …
Run Code Online (Sandbox Code Playgroud) 我想在每次调用函数时打印一个函数(多次调用)中的变量.
是否可以通过gdb自动执行此操作?有条件的印刷......
就像是 ..
void func()
{
if( t == 0 )
x = z+1;
else
x = p+2;
}
Run Code Online (Sandbox Code Playgroud)
我希望在t == 0时打印变量,否则忽略..
Dump of assembler code for function main:
0x0804833e <+0>: push %ebp
0x0804833f <+1>: mov %esp,%ebp
0x08048341 <+3>: sub $0x8,%esp
0x08048344 <+6>: and $0xfffffff0,%esp
0x08048347 <+9>: mov $0x0,%eax
0x0804834c <+14>: add $0xf,%eax
0x0804834f <+17>: add $0xf,%eax
0x08048352 <+20>: shr $0x4,%eax
0x08048355 <+23>: shl $0x4,%eax
0x08048358 <+26>: sub %eax,%esp
=> 0x0804835a <+28>: movl $0x10,-0x4(%ebp)
0x08048361 <+35>: movl $0x0,-0x8(%ebp)
0x08048368 <+42>: pushl -0x4(%ebp)
0x0804836b <+45>: call 0x8048334 <myfunc1 at test.c:4>
0x08048370 <+50>: add $0x4,%esp
0x08048373 <+53>: pushl -0x8(%ebp)
0x08048376 <+56>: call 0x8048339 <myfunc2 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试调试(使用gdb)使用POSIX线程的多线程程序。
我收到类似这样的消息:
Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.
Run Code Online (Sandbox Code Playgroud)
好像该库未使用-g选项进行编译。
我在哪里可以找到这个图书馆?我试图在网络上找到它,但没有得到正确的答案...
请帮忙。
[cprg]$ cat test.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int i=10;
printf("i=%d\ni++=%d\n++i=%d\n",i,i++,++i);
return 0;
}
[cprg]$ make
gcc -g -Wall -o test test.c
test.c: In function ‘main’:
test.c:7: warning: operation on ‘i’ may be undefined
test.c:7: warning: operation on ‘i’ may be undefined
[cprg]$ ./test
i=12
i++=11
++i=12
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会发生这件事.请问有谁可以详细解释我这里发生了什么?