This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: ANSI C / assignment makes pointer from integer
- To: Sebastian Ude <ude at handshake dot de>
- Subject: Re: ANSI C / assignment makes pointer from integer
- From: Bill Wendling <wendling at ncsa dot uiuc dot edu>
- Date: Wed, 8 Aug 2001 16:13:20 -0500
- Cc: gcc at gcc dot gnu dot org
- References: <20010807122255.420A596D37@sender.ngi.de>
Also sprach Sebastian Ude:
}
} Assume this (very common) situation:
}
} [...]
}
} char *s;
}
} s = strdup("foo");
}
} [...]
}
} Looks pretty harmless, doesn't it ?
} But both gcc 2.95.3 and egcs 1.1.2 give me the following warning when
} compiling this code with -ansi:
}
} warning: assignment makes pointer from integer without a cast
}
} The warning disappears if you would change the code like this:
}
} [...]
}
} char *s;
}
} s = (char*) strdup("foo");
}
} [...]
}
} But why ?
}
} What kind of ANSI / ISO rule do I violate ?
} Why the hell is a cast neccessary at this point in order not to provoke a
} warning when compiling with -ansi ?
}
If you don't have the proper header files, then "strdup" will be declared
automagically as returning a type "int". Hence, the problem. If you
include the proper header, this should go away.
--
|| Bill Wendling wendling@ncsa.uiuc.edu
|| Coding Simian