c - Define array and symbolic indices at same time -
I am trying to think about (C) in a clever way so that one of the stars with symbolic names Arrays can be prepared (Enum or #define), something like building for easy maintenance in one:
constants four * wire [] = {m (STR_YES, "yes"), M (STR_NO, "No"), M (STR_MAYBE, "maybe")};
where the result will be equal:
const char * strings [] = {"yes", "no", "may be"}; Anum Index {STR_YES, STR_NO, STR_MAYBE}; (Or #defined STR_YES 0, etc.)
But in this case how am I drawing a blank to create M-macro.
Any clever ideas?
Technology used in the Clan compiler source which is a list of .def files , Which is designed like a C file and can be easily maintained without touching other code files that use it. For example:
#ifndef keyword #define keyword (x) #endif #ifndef LAST_KEYWORD #define LAST_KEYWORD (x) keyword (x) #endif keyword (return) keyword (switch) keyword ( ). LAST_KEYWORD (if) #undef KEYWORD #undef LAST_KEYWORD Now, the file in it is as follows:
/ * Some code * / #define KEYWORD (X) #X, #define LAST_KEYWORD (X) #X const char * strings [] = {#include "keywords.def"}; #defineKEYWORD (X) kw _ ## X, #define LAST_KEYWORD (X) kw _ ## X enum {#include "keywords.def"}; In your case, you can do this if you can stay with STR_yes , STR_no ... such as You can use the same approach given above. Otherwise, just pass the macro two things to a lowercase name and an uppercase name. Then you can stretch the way you want to do the above,
Comments
Post a Comment