Ike Naar
5/5/2011 1:02:00 PM
On 2011-05-05, Bill Cunningham <nospam@nspam.invalid> wrote:
> I am not quite sure what is going on here but this is my tested and
> compiled code. As written below at compile time I get this warning.
>
> 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*. Now if I change that char p[] to a char *p I get a
> segmentation fault. What's up with that?
Apparently not all versions of the GNU toolset provide the strfry() function.
If the function is not provided, the strfry(p) call in your program is
a call to an undefined function, and the compiler will assume int for the
return type. You then assign the (presumably int) returnvalue to char *a,
hence the warning about the pointer-from-integer conversion.