4 ms·
Or you could just use functions to do the same thing. I assure you you did not invent building linked lists on the stack. By the way, you should be wrapping y
by theseoafs 11y ago
Or you could just use functions to do the same thing.
I assure you you did not invent building linked lists on the stack.
By the way, you should be wrapping your giant macros (when they are necessary and useful; they aren't here) in do {} while (0) blocks.
- rumcajz 11y agoNow you made me curios. How would you go about doing it with functions? Keep in mind that the goal is to interleave conditions and the code in switch-like way.
- theseoafs 11y agoThe 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; }