I am designing a C API which among other things has to provide a way to set some double-valued options. To identify the options I use the following enum:
typedef enum
{
OptionA,
OptionB,
...
} Option;
Is it a good idea to use Option as a parameter type in a public API function:
int set_option(Option opt, double value);
or is it better to use int instead:
int set_option(int opt, double value);
considering that I may need to add more options in the future?
Also are there any good examples of existing APIs that demonstrate either approach?
By using an
enumyou are effectively helping the user of your function to know what valid values are available.Of course the drawback is that whenever a new option is added you will need to modify the header and thus the user may need to recompile his code whereas if it is an
inthe may not have to do that.