I need to specify an argument short option (e.g. -F) both as char and char[] constant in c code. In order to maximize code reusage I want to declare a variable which allows me to change the value in one place (a "literal" - not stringly speaking a string or char literal, but in the sense of the abstract concept). I would prefer a solution which solves this exclusively in preprocessor constants and functions/macros or exclusively in c code to a good explanation why this has to be solved in a mixture of both.
I tried/checked out
- to
#define FOREGROUND_OPTION_VALUE 'F'which causes me trouble to transform it to achar[](as preprocessor constant) (writing a macro which stringifies with#causes the'quotes to be stringified as well - to omit the
'quotes which leaves me with the problem of creating the'quotes or create acharanother way. - @PedroWitzel's answer to declare a
char[]and use the 0thcharfor another constant. That's fine, but I'd prefer a way to create thechar[]from thecharbecause that enforces both to be equal (otherwise I'd have to add a compile time assertion thatchar[]isn't longer than1).
The only thing that matters for me is code maintenance, nothing else (like cost in processing the code (during compilation or runtime - have not reflected intensively if there could be any and don't care)).