Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Compilation problems??

Re: Compilation problems??

From: Alicia Carla Longstreet <carla_at_ici.net>
Date: 1997/08/14
Message-ID: <33F359DD.4855@ici.net>#1/1

GAZZA wrote:
>
> > It is strange, because I have specifically
> > defined the return value of the function as a
> > pointer to char. Yet, the error message is
> > saying that the return value is an int!
>
> Yes, this is because you call the function before you
> define it (line 86 precedes line 96). This means that
> the compiler decides that the function must return an
> int (the default return type for functions in C).
>
> This can be solved with a prototype:
>
> > #include "stdio.h"
>
> Should probably be
>
> #include <stdio.h>
>
> Here you need to insert:
>
> char *checkvalue(void);
>
> > int main()
>
> int main(void)

This does the same thing as int main(), but is more visible as to your intent.
In any event, the main function will get called with two arguments, the number of arguments and the command line.

> > {
> >
> > char *ls_returnvalue;
> >
> > ls_returnvalue = "";
>
> In effect, this does nothing, since on the very next line
> you re-assign the value of the pointer. This could be
> safely omitted.
>
> > ls_returnvalue = checkvalue (); /* line 86 */
>
> This will work now.
>
> > printf("ls_returnvalue is: %s\n", ls_returnvalue);
> >
> > exit(0); /* This is fine. */
>
> The standard allows exit to return EXIT_SUCCESS or
> EXIT_FAILURE, both of which are defined in stdlib.h;
> personally, I would simply change this to:

There is NOTHING in the standard that requires a program to return either EXIT_SUCCESS or EXIT_FAILURE, the Standard allows ANY INTEGER VALUE to be returned, with either exit() or a simple return.

My programs often use the exit code to indicate the nature of the failure, this way, shell scripts can do more than simply check for success or failure, they can take one of several actions based on the nature of the error.

As for using a simple return rather than exit() this is foolish advice. exit() offers some excellent features, notably atexit() which allows the programmer to define one or more functions to called by exit(). You can specify up to 32 functions.

-- 
*********************************************************
* Alicia Carla Longstreet     carla_at_ici.net             *
* Supporter of the campaign against grumpiness on c.l.c *
*********************************************************
*      Children,                                        *
*      We spend two years teaching them to talk...      *
*      and 20 years trying to get them to shut up!      *
*********************************************************
The money spent on an abortion,
as any woman may find out,
can better be spent on other things,
like taking the kids to an amusment park, or on vacation.
Received on Thu Aug 14 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US