Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6000457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:41:46+00:00 2026-05-23T00:41:46+00:00

I’m writing a simple parser to read the config file.The config.h interface have only

  • 0

I’m writing a simple parser to read the config file.The config.h interface have only three
main functions they are in brief as follows,

config_init();
config_dinit();
config_parse();
config_read_value();

My question is those functions will emit different type of errors , for a example,

config_init() emit , FILE_NOT_FOUND,FILE_EOF_ERROR,FILE_OPEN_ERROR, ...
config_dinit() emit , NOT_INIT_ERROR ,
config_parse() emit , PARSE_ERROR, OVERFLOW_ERROR, INVALID_CHARACTER_FOUND_ERROR,...
config_read_value() emit, SECTION_NOT_FOUND,KEYWORD_NOT_FOUND,OVERFLOW_ERROR,NOT_INITIALIZED_ERROR,INVALID_STATE_ERROR,... etc.

Then I create enums for each function, for by using these names , 
enum Config_ParseError{...} , enum Config_InitError{...} ,enum Config_ReadValueError{..}
etc.

Some enum values are overlapping each other and hit “compiler error” too. like
OVERFLOW_ERROR,

I’m opening for your suggestions,

and I have done a quick research on the google and found that most popular IRC client
source code have defined the enums like this,

enum {
    CMDERR_OPTION_UNKNOWN = -3, /* unknown -option */
    CMDERR_OPTION_AMBIGUOUS = -2, /* ambiguous -option */
    CMDERR_OPTION_ARG_MISSING = -1, /* argument missing for -option */

    CMDERR_UNKNOWN, /* unknown command */
    CMDERR_AMBIGUOUS, /* ambiguous command */

        CMDERR_ERRNO, /* get the error from errno */
    CMDERR_NOT_ENOUGH_PARAMS, /* not enough parameters given */
    CMDERR_NOT_CONNECTED, /* not connected to server */
    CMDERR_NOT_JOINED, /* not joined to any channels in this window */
    CMDERR_CHAN_NOT_FOUND, /* channel not found */
    CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
    CMDERR_ILLEGAL_PROTO, /* requires different chat protocol than the active server */
    CMDERR_NOT_GOOD_IDEA, /* not good idea to do, -yes overrides this */
    CMDERR_INVALID_TIME, /* invalid time specification */
    CMDERR_INVALID_CHARSET, /* invalid charset specification */
    CMDERR_EVAL_MAX_RECURSE, /* eval hit recursion limit */
    CMDERR_PROGRAM_NOT_FOUND /* program not found */
};

it defines enum without any name, is that a good style?Then why what are the reasons for
that?

Seriously need some more good naming decisions. Please don’t hurt me I just only
start reading “writing beautiful C code” book.

Thanks In Advance.
Sandun.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:41:47+00:00Added an answer on May 23, 2026 at 12:41 am

    I’m usually a fan of one set of error returns for an entire library. This way in consumers they don’t have to worry about “was the -1 bad input to X or could not connect to Y”.

    I’m also a fan of E_ prefixes, but really any will do:

    enum _config_error
    {
        E_SUCCESS = 0,
        E_INVALID_INPUT = -1,
        E_FILE_NOT_FOUND = -2, /* consider some way of returning the OS error too */
        ....
    };
    
    /* type to provide in your API */
    typedef enum _config_error error_t;
    
    /* use this to provide a perror style method to help consumers out */
    struct _errordesc {
        int  code;
        char *message;
    } errordesc[] = {
        { E_SUCCESS, "No error" },
        { E_INVALID_INPUT, "Invalid input" },
        { E_FILE_NOT_FOUND, "File not found" },
        ....
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.