DHOLLINGSWORTH2 said:
And I could pretend to be an ass and say that none of youtr examples work
becuase they have no main proc in them.
And I may be wrong, but Type casting is a no no, then why is it in the
STANDARD?
Type casting is in the standard because there are cases where it can
be used correctly and usefully. For example, if you want have a
pointer-to-int variable and you want to show its value, you can use:
int *ptr = <whatever>;
printf("ptr = %p\n", (void*)ptr);
This cast is necessary and appropriate because the call to printf()
doesn't provide a context that forces an implicit conversion.
In most other cases, though, C's implicit conversion rules make casts
unnecessary (and often dangerous).
The OP was asking about an implementation-defined function that
returns a char*; an implementation-defined header provides a prototype
for the function. If the header is not included, the compiler sees a
call and doesn't know what type it returns. In C90, the language
requires the compiler to assume (incorrectly in this case) that it
returns int, so it will generate code that assumes this. Casting the
result to char* doesn't fix the problem, it hides it. The result is
that the compiler generates code takes the (potentially nonexistent)
int result of the function and converts it to char*. This may happen
to work on some systems, but will fail on others.
For the call to work properly, the compiler must know that the
function returns a char*. The way to do this is to include the header
(or to declare the function explicitly, but it's almost always better
to include the header).
Your response suggested that casting the result would be a solution.
You were mistaken. Several people pointed out your error. This is
not being an "ass"; indeed, leaving your error uncorrected would have
been rude to you and to all the readers who might follow your advice.
Making mistakes isn't a horrible sin. I've made plenty myself, and
I'm glad when they're corrected. If someone points out that you've
made a mistake, don't take it personally.
And if you want to be taken seriously, I strongly suggest you stop
top-posting. We're not asking you this just to be annoying; your
posting style really does make your articles more difficult to read.
You've already been told in detail why top-posting is a bad idea.