1 /** Tests argument passing to functions via va_args.
2 Assumes that up to the first two arguments can be passed in registers.
11 /* gcc 3.3 throws a warning, if char is in '...' */
12 #if defined(PORT_HOST) || defined (__SDCC_pdk13) || defined (__SDCC_pdk14) || defined (__SDCC_pdk15) || defined (__SDCC_f8)
20 returnFirstArg(int marker
, ...)
26 i
= va_arg(ap
, {type1
});
30 LOG(("Returning %d\n", i
));
35 returnSecondArg(int marker
, ...)
41 UNUSED(va_arg(ap
, {type1
}));
42 i
= va_arg(ap
, {type2
});
46 LOG(("Returning %d\n", i
));
50 #ifndef __SDCC_pdk14 // Lack of memory
52 returnSecondArgCopy(int marker
, ...)
57 va_start(ap1
, marker
);
58 UNUSED(va_arg(ap1
, {type1
}));
60 i
= va_arg(ap2
, {type2
});
65 LOG(("Returning %d\n", i
));
70 returnThirdArg(int marker
, ...)
76 UNUSED(va_arg(ap
, {type1
}));
77 UNUSED(va_arg(ap
, {type2
}));
78 i
= va_arg(ap
, {type3
});
82 LOG(("Returning %d\n", i
));
94 LOG(("First arg: %u\n", returnFirstArg(marker
, ({type1
})123, ({type2
})45, ({type3
})67)));
95 ASSERT(returnFirstArg(marker
, ({type1
})123, ({type2
})45, ({type3
})67) == ({type1
})123);
96 ASSERT(returnFirstArg(marker
, ({type1
})-123, ({type2
})45, ({type3
})67) == ({type1
})-123);
97 #ifndef __SDCC_pdk14 // Lack of memory
98 ASSERT(returnSecondArg(marker
, ({type1
})1, ({type2
})-23, ({type3
})64) == ({type2
})-23);
99 ASSERT(returnSecondArg(marker
, ({type1
})1, ({type2
})8, ({type3
})64) == ({type2
})8);
101 ASSERT(returnSecondArgCopy(marker
, ({type1
})1, ({type2
})-23, ({type3
})64) == ({type2
})-23);
102 ASSERT(returnSecondArgCopy(marker
, ({type1
})1, ({type2
})8, ({type3
})64) == ({type2
})8);
104 ASSERT(returnThirdArg(marker
, ({type1
})-33, ({type2
})-34, ({type3
})-35) == ({type3
})-35);
105 ASSERT(returnThirdArg(marker
, ({type1
})-33, ({type2
})-34, ({type3
})35) == ({type3
})35);