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