This, this right here... is why people hate macros...
-
Bruh
#define SUBMIT_FIELD(p) \
do { \
if (!quoted) \
entry_pos -= spaces; \
if (p->options & CSV_APPEND_NULL) \
((p)->entry_buf[entry_pos]) = '\0'; \
if (cb1 && (p->options & CSV_EMPTY_IS_NULL) && !quoted && entry_pos == 0) \
cb1(NULL, entry_pos, data); \
else if (cb1) \
cb1(p->entry_buf, entry_pos, data); \
pstate = FIELD_NOT_BEGUN; \
entry_pos = quoted = spaces = 0; \
} while (0)I mean dude, make it an inline function already. :laugh:
Jeremy Falcon
That's why function templates were created in C++. All of the compile time features without adding overhead or degradation in execution speed. When I am coding in C++, I *rarely* use/utilize macros. Which isn't to say that macros, properly implemented aren't useful. Take, example, the need to "stringize" a set of characters. You can't really beat:
#define STRINGIZE(x) #x
:) One more thing... too often, macros are used to provide some way to represent a value, as opposed to using aconst
variable declaration. One should eschew this:#define PI 3.1415927f
in favor of this:const float PI = 3.1415927f;
-
That's why function templates were created in C++. All of the compile time features without adding overhead or degradation in execution speed. When I am coding in C++, I *rarely* use/utilize macros. Which isn't to say that macros, properly implemented aren't useful. Take, example, the need to "stringize" a set of characters. You can't really beat:
#define STRINGIZE(x) #x
:) One more thing... too often, macros are used to provide some way to represent a value, as opposed to using aconst
variable declaration. One should eschew this:#define PI 3.1415927f
in favor of this:const float PI = 3.1415927f;
1,000% agree. To be honest, my C++ is weak. I've always done "C in C++" but maybe it's time I revisit that.
Jeremy Falcon
-
Greetings Kind Regards May I please inquire the alternative. I do not see how a function inline or not would be sufficient as the macro is referencing many local variables. All those terms of course can be passed to a function but now you have an ugly function call. In my own current project a number of methods perform identical logic utilizing local variables of identical name as part of their different duties. Though the macro itself is ugly has heck and difficult to debug the aforementioned methods are much cleaner in appearance. I would be happy and eager to learn of a superior method. Thank You Kindly
appearance has nothing to do with test, maintainability and understanding. Don't get me wrong, there is a place for macros - SIMPLE macros. I'll get silly, I can take a function at 1000 lines and turn it into a macro. How is that helpful? #define _DO_STUFF_ No. Sorry, just no. Modern compilers are efficient. People that write huge macros are either using their preferences, trying to be cute, or have never been held accountable. It's a disease, get therapy.
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.