This works for me:
but I agree with Shiro that this is quite a nasty bit of code. A function would be much neater...
#define DIVMOD(x,y,d,r) d = ((y)==0) ? 0, r=0 : (x)/(y), r = (x) % (y)
...and unless you are doing loads of these operations isn't going to significantly slow down your program.
void DivMod(int x, int y, int * pd, int * pr)
if (y == 0)
*pd = *pr = 0;
*pd = x / y;
*pr = x % y;
If you insist on using a macro use something like:
where pd and pr are pointers.
#define DIVMOD(x,y,pd,pr) *pd = ((y)==0) ? 0, *pr=0 : (x)/(y), *pr = (x) % (y)