B
Bill Cunningham
Marc said:Le 05-05-2011 said:p.c: In function `main':
p.c:9: warning: assignment makes pointer from integer without a cast
I don't see the int in this code.
#include <stdio.h>
#include <string.h>
int main(void)
{
char p[] = "hello to all";
char *a;
printf("%s\n", p);
printf("%s\n", a = strfry(p)); //error on this line.
return 0;
}
strfry() is a GNU extension. It takes a char* as is sole argument and
returns a char*.
When I compile, I get also warning
warning: implicit declaration of function 'strfry'
and when I read the man page, I see that you need to
define macro _GNU_SOURCE to use this function.
My man page does say this. It doesn't mention defining any macro. Man
pages aren't the same. Try this link and you'll see what I mean.
http://linux.die.net/man/3/strfry
So, without _GNU_SOURCE, the function strfry is assumed
to return an int, and the expression
a = strfry(p)
puts an int into a char*.
Now if I change that char p[] to a char *p I get a
segmentation fault. What's up with that?
Because
char * p = "hello to all";
defines a pointer p on a *read only* string "hello to all",
and strfry tries to write into a read-only memory?
Marc Boyer