samedi 25 avril 2015

How to reuse a literal in a char and a one-character string variable?

I need to specify an argument short option (e.g. -f) both as char and char[] 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

  • to #define FOREGROUND_OPTION_VALUE 'F' which causes me trouble to transform it to a char[] (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 a char another way.

Aucun commentaire:

Enregistrer un commentaire