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. Isn't the C/C++ macro considered to be poor style? It's being used at coder contests!

Isn't the C/C++ macro considered to be poor style? It's being used at coder contests!

Scheduled Pinned Locked Moved The Lounge
c++comquestionannouncementcareer
11 Posts 11 Posters 0 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.
  • S Offline
    S Offline
    swampwiz
    wrote on last edited by
    #1

    I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

    P B N D C 8 Replies Last reply
    0
    • S swampwiz

      I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      They're awesome. Misused, but awesome.

      1 Reply Last reply
      0
      • S swampwiz

        I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

        B Offline
        B Offline
        Bob Nadler
        wrote on last edited by
        #3

        I'm not sure if they're considered "poor style", but C/C++ macros are very powerful. I've worked on projects where they were used to essentially provide a DSL. That was many years ago, but I have fond memories of the C preprocessor and C++ templates (the 'real' thing). Still miss both in Java/C#.

        Bob on Medical Device Software [^]

        1 Reply Last reply
        0
        • S swampwiz

          I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

          N Offline
          N Offline
          Nisamudheen
          wrote on last edited by
          #4

          In fact Macros are really powerful tool. It is one of the best way by which one can talk to the underlying compiler and by which the compiler can talk to you. Yes compiler can talk to you by the means of Predefined Macros. If we look at the "Preprocessor Definitions" of Visual Studio editor of a C++ project, there are a lots of things configured which can be done otherwise using #define macros. Following are some of the application areas of macros. 1. Platform based API declarations. Platform can be different Operating Systems, it can be 32 bit or 64 bit. 2. Generation of conditional code. 3. Switching between UNICODE and Multi-byte. 4. Prevention of multiple times inclusion of header files. Achieved using #ifndef,#define,#endif. 5. API generation when used in conjunction with template meta programming.

          M 1 Reply Last reply
          0
          • N Nisamudheen

            In fact Macros are really powerful tool. It is one of the best way by which one can talk to the underlying compiler and by which the compiler can talk to you. Yes compiler can talk to you by the means of Predefined Macros. If we look at the "Preprocessor Definitions" of Visual Studio editor of a C++ project, there are a lots of things configured which can be done otherwise using #define macros. Following are some of the application areas of macros. 1. Platform based API declarations. Platform can be different Operating Systems, it can be 32 bit or 64 bit. 2. Generation of conditional code. 3. Switching between UNICODE and Multi-byte. 4. Prevention of multiple times inclusion of header files. Achieved using #ifndef,#define,#endif. 5. API generation when used in conjunction with template meta programming.

            M Offline
            M Offline
            Member 12000837
            wrote on last edited by
            #5

            I always thought macros were the function-like things, the rest being preprocessor definitions. Apparently everything substituted by the preprocessor is called a macro. https://gcc.gnu.org/onlinedocs/cpp/Macros.html[^] I personally dislike function-like macros, except for the really simple ones like min and max. They are a real horror to debug.

            1 Reply Last reply
            0
            • S swampwiz

              I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

              D Offline
              D Offline
              den2k88
              wrote on last edited by
              #6

              Poor style? Macros are extremely powerful and used in the right way are faster and can be more useful than templates, classes and functions. Using defines for constants - that's poor style and should be avoided if possible. Const and enums are scoped and reduce namespace pollution - other than misuse of similarly named constants (MAX_CHARS is a perfect name for a lot of max chars things, in different classes may have diffwerent meaning and values. If it is a scoped const you avoid potential deadly pitfalls).

              GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver "When you have eliminated the JavaScript, whatever remains must be an empty page." -- Mike Hankey

              1 Reply Last reply
              0
              • S swampwiz

                I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                To wear out the motorbike tyres in less than a hour is poor riding style, still in motoGP... :rolleyes:

                1 Reply Last reply
                0
                • S swampwiz

                  I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Well so what? They don't have to use "Good Style", whatever that is.

                  1 Reply Last reply
                  0
                  • S swampwiz

                    I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    swampwiz wrote:

                    I have always been told that the macro in C/C++ is considered to be poor style

                    Beware absolutes. They are never right.

                    D 1 Reply Last reply
                    0
                    • S swampwiz

                      I have always been told that the macro in C/C++ is considered to be poor style, yet a snippet of presumably competition code has a ton of them: www.bloomberg.com/news/features/2015-09-25/the-jocks-of-computer-code-do-it-for-the-job-offers?cmpid=BBD092515_BIZ :confused:

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

                      Like most things, they only become poor style when abused / misused.

                      Jeremy Falcon

                      1 Reply Last reply
                      0
                      • P Pete OHanlon

                        swampwiz wrote:

                        I have always been told that the macro in C/C++ is considered to be poor style

                        Beware absolutes. They are never right.

                        D Offline
                        D Offline
                        Daniel Pfeffer
                        wrote on last edited by
                        #11

                        Pete O'Hanlon wrote:

                        Beware absolutes. They are never right.

                        What, never?! Yes, never! What, never?! Well... hardly ever.

                        If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

                        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