- 论坛徽章:
- 0
|
const char *argv[]与char *const argv[]有什么区别?
似乎在Linux下只是给一个警告,但实际的值还是被改变了。
- [root@liang tmp]# gcc -v
- Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
- Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
- Thread model: posix
- gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-34)
- [root@liang tmp]# cat f.c
- #include <stdio.h>;
-
- int main(void)
- {
- const char *pa;
- char a = 'c';
-
- pa = &a ;
- *pa = 'd';
- printf("%c\n", *pa);
- }
- [root@liang tmp]# make f
- cc f.c -o f
- f.c: In function `main':
- f.c:9: warning: assignment of read-only location
- [root@liang tmp]# ./f
- d
- [root@liang tmp]#
复制代码 |
|