Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!apple!voder!pyramid!decwrl!wuarchive!cs.utexas.edu!sun-barr!newstop!grapevine!fiveliter!mhill From: mhill@fiveliter.EBay.Sun.COM (Maurice Hill) Newsgroups: comp.lang.c Subject: Re: Functions returning Error codes or actual info Message-ID: <285@grapevine.EBay.Sen.COM> Date: 11 Sep 90 20:47:48 GMT References: <772@babcock.cerc.wvu.wvnet.edu> <1990Sep11.121531.23065@jarvis.csri.toronto.edu> Sender: news@grapevine.EBay.Sun.COM Lines: 16 flaps@dgp.toronto.edu (Alan J Rosenthal) writes: >vrm@cathedral.cerc.wvu.wvnet.edu (Vasile R. Montan) writes: >> I am making a set of functions which return different types of >>values: strings, integers, doublec, etc. For example: >> char *get_string(); >>However, I would also like the function to return an error code if the >>function fails. I cannot just return a NULL pointer because I want >>the function to be the same as all of the other get_xxx's. Perhaps you could implement a different error strategy. Instead of returning an error code, set a global such as is done with errno. Errno is an index into an array of predefined error messages. You can access the list yourself or uce the function `error("msg") to print out your msg plus the error message that corresponds to errno.