
Returning an array of int from a function
Quote:
>Jack,
>Thanks for the help! You gave me just what I needed -- a concrete
>example. One thing I did notice on my implementation is that I got a
>compiler warning on the malloc statement complaining of not having a
>cast (although the program ran fine). After modifying to (int
>*)malloc , the warning vanished.
In ANSI C a cast is unnecessary and best avoided. The compiler warning
could mean one of several things:
1. malloc() hasn't been correctly declared. Make sure the code you compiled
really does have #include <stdlib.h>.
2. You are using a very old compiler/library which doesn't declare malloc
properly or declares it as returning char * instead of the correct ANSI
void * return. In that case you really should consider getting a better
compiler. Trying to learn C on an old compiler is going to cause more
problems than it is worth.
3. You aren't using a C compiler. C++ compilers would complain about the
conversion. Always be clear what language you are writing in. If it is
C make sure your compiler is configured as a C compiler, if C++ you
would be better off using C++ constructs like new.
While ANSI C compilers could warn about an implicit conversion from void *
to int * (they can warn about anything they like) it is extremely unlikely
that one would, at leastnot without some bizarre command line options.
--
-----------------------------------------
-----------------------------------------