Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. This, this right here... is why people hate macros...

This, this right here... is why people hate macros...

Scheduled Pinned Locked Moved The Lounge
23 Posts 10 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jeremy Falcon

    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

    S Offline
    S Offline
    Stacy Dudovitz
    wrote on last edited by
    #21

    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 a const variable declaration. One should eschew this: #define PI 3.1415927f in favor of this: const float PI = 3.1415927f;

    J 1 Reply Last reply
    0
    • S Stacy Dudovitz

      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 a const variable declaration. One should eschew this: #define PI 3.1415927f in favor of this: const float PI = 3.1415927f;

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #22

      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

      1 Reply Last reply
      0
      • B BernardIE5317

        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

        C Offline
        C Offline
        charlieg
        wrote on last edited by
        #23

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups