d*******e 发帖数: 49 | | a******e 发帖数: 95 | 2 use gdb to trace.
it is very common that a program runs correctly in one OS, but not
in another.
【在 d*******e 的大作中提到】 : 是在程序返回的时候出错。 : 会是为啥?
| a**n 发帖数: 313 | 3 without the code, how can others help you? BTW, I am not an expert...
But for example, Linux with gcc deals with string constant differently
with other unix platforms. This is an example which core dumped on Linux
but not on others:
/>cat test.c
#include
#include
#include
int main()
{
char * p = "hello";
*p='p';
printf("%s\n", p);
return 0;
}
/Tru64Unix>cc -V
Compaq C V6.3-025 on Compaq Tru64 UNIX V5.1 (Rev. 732)
【在 d*******e 的大作中提到】 : 是在程序返回的时候出错。 : 会是为啥?
| o**v 发帖数: 1662 | 4 这code是合法但不合理的样子......
各个cc的实现不一样吧.
【在 a**n 的大作中提到】 : without the code, how can others help you? BTW, I am not an expert... : But for example, Linux with gcc deals with string constant differently : with other unix platforms. This is an example which core dumped on Linux : but not on others: : />cat test.c : #include : #include : #include : int main() : {
| t*****t 发帖数: 72 | 5 you may try different compilers, like transfering from gcc
to g++. Sometimes this helps..
【在 d*******e 的大作中提到】 : 是在程序返回的时候出错。 : 会是为啥?
| t**c 发帖数: 97 | 6 why this one does not work for gcc?
or more specifically, if I change char *p to char p[], it works fine.
any particular reason for this?
【在 a**n 的大作中提到】 : without the code, how can others help you? BTW, I am not an expert... : But for example, Linux with gcc deals with string constant differently : with other unix platforms. This is an example which core dumped on Linux : but not on others: : />cat test.c : #include : #include : #include : int main() : {
| a**n 发帖数: 313 | 7 if you define char *p = "hello";
then it mean p pointer to a string literal, which is const, and you are
not supposed to change it. You can refer C++ primer or any other book
for this.
If you define it as char p[], it is a different story.
【在 t**c 的大作中提到】 : why this one does not work for gcc? : or more specifically, if I change char *p to char p[], it works fine. : any particular reason for this?
| t**c 发帖数: 97 | 8 that's what I suspect, but just don't know the implementation details.
thanks.
【在 a**n 的大作中提到】 : if you define char *p = "hello"; : then it mean p pointer to a string literal, which is const, and you are : not supposed to change it. You can refer C++ primer or any other book : for this. : If you define it as char p[], it is a different story.
|
|