5 ms·
I've seen people suggest enums, strings, and named parameters. I'm surprised that nobody seems to have mentioned binary flags, because sometimes they work real
by notacoward 12y ago
I've seen people suggest enums, strings, and named parameters. I'm surprised that nobody seems to have mentioned binary flags, because sometimes they work really well.
/* caller */
doSomething (arg1, arg2, XYZ_SYNC);
/* platform 1 */
#define XYZ_SYNC 0
#define XYZ_ASYNC 0x01
/* platform 2 */
#define XYZ_SYNC 0x01
#define XYZ_ASYNC 0
For extra credit, you can define flags so that one or the other must be specified, so both can't be, etc. Then you can still pack multiple flags into a single parameter, to reduce argument-passing time and space. I know it's all old-school and everything, but it has worked well for a lot of people over the years.