Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22091

Is there any way to split gcc macro arguments?

$
0
0

I write code that can run on GPU or CPU. In case of CUDA presence wrapper try to run function on GPU. In case of error (no memory for example) it try to run it on CPU. In case of error again it returns 0, otherwise it returns 1. In case of CUDA absence wrapper only try to run function on CPU.

Here is my macro:

#ifdef CUDA_FOUND
#define SET_F(FNARGS, FNSTRIP) int FNARGS{  \
    if(!Only_CPU) if(CU ## FNSTRIP) return 1;\
    if(CPU ## FNSTRIP) return 1;            \
    return 0;                               \
}
#else
#define SET_F(FNARGS, FNSTRIP) int FNARGS{  \
    if(CPU ## FNSTRIP) return 1;            \
    return 0;                               \
}
#endif // CUDA_FOUND

To define new function I call it so:

SET_F(fillrandarr(size_t sz, char *arr), fillrandarr(sz, arr))

Question: is there a way to simplify this macro splitting arguments of FNARGS to compose FNSTRIP? I.e. to shorten the definition above to

SET_F(fillrandarr(size_t sz, char *arr))

?


Viewing all articles
Browse latest Browse all 22091

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>