-1

Is there a way to define macro for value in array:

For exemple I have :

#define COMSS_GETNBERNEWVALUE       uca1_NbreReceivedValue
#define COMSS_GETNBERNEWVALUE2      uca2_NbreReceivedValue
#define COMSS_GETNBERNEWVALUETEST   uca6_NbreReceivedValue

And I would like to store 2 similar data in a macro definition. Something like this:

#define COMSS_GETNBERNEWVALUE[3]   {uca1_NbreReceivedValue,uca2_NbreReceivedValue, uca6_NbreReceivedValue}

Clément
  • 1,128
  • 7
  • 21

1 Answers1

1

You can't do it with [] but you can do this:

#define COMSS_GETNBERNEWVALUE(a)   uca##a##_NbreReceivedValue

Then COMSS_GETNBERNEWVALUE(1) will be substituted with uca1_NbreReceivedValue, COMSS_GETNBERNEWVALUE(2) will be substituted with uca2_NbreReceivedValue etc.

Bu you cannot use this method if instead of having uca1_NbreReceivedValue, uca2_NbreReceivedValue etc. you have ucaFirst_NbreReceivedValue, uca1_NbreReceivedValue.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • I didn't know that but it wouldn't be good for my case since `a` is not equal and could be absolutly not related to the name of `ucX_NbreReceivedValue` – Clément Nov 21 '19 at 10:15
  • 1
    @Clément in that case I suppose you can't do it with macros – Jabberwocky Nov 21 '19 at 10:24