3 ms·
The goal is to implement the desired functionality in a comprehensible way. Given that, the best option would be to use an array, and to initialize it with the
by theseoafs 11y ago
The goal is to implement the desired functionality in a comprehensible way. Given that, the best option would be to use an array, and to initialize it with the easy array intialization syntax that C provides:
struct select_condition conds[] = {
{ channel_1, SELECT_OUT, NULL, 42 },
{ channel_2, SELECT_IN, &i, 0 }
};
No need to overcomplicate it or stuff a bunch of functionality into macros in order to make C look like some other language.
- rumcajz 11y agoThe goal is not to look like golang but to maintain locality: Implementation of one thing should be at one place, not at two different places.
- kayamon 11y agoSeems like the 'classic' C way to go about it would be to use scanf/printf-style format strings: int mode = select("<%i | >%i", channel1, 42, channel2, &i); switch(mode) { case 0: foo(); break; case 1: bar(i); break; }