Isn't the C/C++ macro considered to be poor style? It's being used at coder contests!
-
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:
-
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:
They're awesome. Misused, but awesome.
-
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:
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#.
-
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:
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.
-
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.
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.
-
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:
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
-
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:
-
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:
-
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:
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.
-
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:
Like most things, they only become poor style when abused / misused.
Jeremy Falcon
-
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.
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