How can I define several similar macros using "##"?

I don't know if there is any guy asking the same question, but I couldn't find him using advanced search here with [c] [macro] "##".

I want to define multiple macros like this:

#define CHANNEL_0  0
#define CHANNEL_1  1
...
#define CHANNEL_31 31

      

Can I use this ## character to do it in a simple way? And How? Or maybe there are some ways?

Thank!

+3


source to share


1 answer


I don't think "##" is the best solution here. Why not just use an enum? I see no reason why you couldn't use it if you only want the numbers 0 to 31.

enum eChannel {
    Channel0, /* evaluates to 0 */
    Channel1, /* evaluates to 1 */
    ...
    Channel31 /* evaluates to 31 */
};

      



And the usage is the same as C # defines

if(channel == Channel1) do_smth();

      

+3


source







All Articles