TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Robin Sheppard
from: George White
date: 1998-07-23 07:52:00
subject: Beginner`s Questions

Hi Robin.

You wrote to Patrick Dempster:

RS> GW> the return should be:

RS> GW> return EXIT_SUCCESS;

RS> PD> What value should EXIT_SUCCESS ( a constant i assume ) be defined as
RS> PD> ??

RS>Well, it depends what your function is doing.  If it's returning the value
RS>of a calculation, such as a math routine might, then you'll return that
RS>value.  If it's returning a success/failure flag, you'll probably just be
RS>returning 0 or 1, then you could #define your constants as such.  A more
RS>elegant function might return 0 for success, or one of a number of nonzero
RS>values if an error occurred, with the value corresponding to the type of
RS>error that occurred- hopefully the calling code can use this to fix the
RS>problem, and try the function call again, or at least print a friendly
RS>(well, as friendly as they get) error message on screen- something a little
RS>less cryptic than a simple error number or CPU register dump, which is
RS>meaningless to the casual user.  A third class of function returns a
RS>pointer to specified data, or a NULL pointer to indicate failure.  Almost
RS>all memory-allocation and string functions fit this category.

The use of EXIT_SUCCESS (and EXIT_FAILURE) is mainly for main() and the
values are #defines in stdlib.h. You can (and indeed should) use other
return values from main() to pass extra information about fail reasons
if this is appropriate for the application. For internal functions the
return value is determined by the way the function is designed (result
of operation, pointer to something), but EXIT_SUCESS & EXIT_FAILURE are
appropriate for functions that only return a success/failure indication.

George

 * SLMR 2.1a * Computers eliminate spare time.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (2:440/4)
SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728
SEEN-BY: 639/252 670/213 218
@PATH: 440/4 255/1 252/356 140/1 270/101 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.