回复 5楼 embed_xuel
不是这个问题,这两种方法定义是没有问题的。
crazyjudas@ubuntu:~$ make reverse_string
cc -Wall -g
reverse_string.c
-o reverse_string
reverse_string.c: In function ‘reverse_string’:
reverse_string.c:24:4: error: expected ‘;’ before ‘}’ token
make: *** [reverse_string] Error 1
crazyjudas@ubuntu:~$ make reverse_string
cc -Wall -g
reverse_string.c
-o reverse_string
crazyjudas@ubuntu:~$ ./reverse_string
Segmentation fault
crazyjudas@ubuntu:~$ make reverse_string
cc -Wall -g
reverse_string.c
-o reverse_string
crazyjudas@ubuntu:~$ ./reverse_string
Segmentation fault
crazyjudas@ubuntu:~$ valgrind ./reverse_string
==2367== Memcheck, a memory error detector
==2367== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==2367== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==2367== Command: ./reverse_string
==2367==
==2367== Invalid read of size 1
==2367== at 0x8048471: reverse_string (reverse_string.c:18)
==2367==
by 0x80484DC: main (reverse_string.c:35)
==2367==
Address 0xffffffff is not stack'd, malloc'd or (recently) free'd
==2367==
==2367==
==2367== Process terminating with default action of signal 11 (SIGSEGV)
==2367==
Access not within mapped region at address 0xFFFFFFFF
==2367==
at 0x8048471: reverse_string (reverse_string.c:18)
==2367==
by 0x80484DC: main (reverse_string.c:35)
==2367==
If you believe this happened as a result of a stack
==2367==
overflow in your program's main thread (unlikely but
==2367==
possible), you can try to increase the size of the
==2367==
main thread stack using the --main-stacksize= flag.
==2367==
The main thread stack size used in this run was 8388608.
==2367==
==2367== HEAP SUMMARY:
==2367==
in use at exit: 0 bytes in 0 blocks
==2367==
total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==2367==
==2367== All heap blocks were freed -- no leaks are possible
==2367==
==2367== For counts of detected and suppressed errors, rerun with: -v
==2367== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 11 from 6)
调试的结果是swap=*end; 出了问题 , 不知道为什么会这样。
我按照你说的改了,还是这样。