Question : How to use same software for passing argument as value in one platform and address in another?

In Platform A, the function argument is unsigned value.  In Platform B, the interface requires address to be passed instead of the value.

For the higher software layer that is making the function call, the requirement is to use same set of files for Platform A and Platform B.  I created the following macro to ensure function running in Platform A get the value and function running in Platform B gets the address:

#ifdef PLATFORM_B
  #define CHANNEL  &(cnfg->channel)
#else
  #define CHANNEL  cnfg->channel
#endif

Is there a better way to write this macro?
Is there another solution besides the macro?


The higher layer software making the function call is as follows:

typedef void * channel_t;  /* in Platform B */
/* channel_t is unsigned in Platform A */

void set_priority(channel_t channel, unsigned value);

typedef struct cnfg_s   cnfg_t;

typedef struct pulseidc_cnfg_s
{
     unsigned    channel;
     ...
};


void
some_init(work_t  *work,
              cnfg_t  *cnfg
             )
{
...  
   set_priority(CHANNEL,   DIS_PRI);

...

Answer : How to use same software for passing argument as value in one platform and address in another?

>> I can't provide this information because it's proprietary.

Now I understand why you're reluctant to answer my questions clearly ;)

Since I don't know what API you're talking about, I don't have enough information to help you. You'll have to check in the API documentation whether there is a function that converts a channel_t value to its numeric id.

Something like :

        int getChannelId(channel_t c) {
                /* the implementation here would be different on both platforms, but hidden from you */
        }

In that case, you can simply call this function :

        if (
          (getChannelId(cnfg->channel) >= 0)  &&
          (getChannelId(cnfg->channel) <= 15)
        )
Random Solutions  
 
programming4us programming4us