News for hackers. Stuff that matters.
Re:How to properly use macros in C by cjensen on Sunday December 10, 2017 @03:38PM (#15893375)
If you're going to write a long lecture to people, it's helpful to do some Googling to fact-check your own understanding.

The claim that macros do not exist in other languages is incorrect. Every sensible assembly language compiler has macros to help the programmer with boilerplate.

The claim that multiline macros are a problem is correct. Suggesting that a workaround is to use a naming convention for such macros is crazy-talk. There is a time-honored pattern you use to fix this in the macro itself: wrap the macro with "do { <macro content> } while (0)".

Re:How to properly use macros in C by bluetomcat on Sunday December 10, 2017 @04:46PM (#15893662)
The goal of this article is not to provide some genuine insight to the topic, but to serve as a publicity stunt for the largest code academy in Bulgaria, dubiously called "Software University". On numerous other occasions their lecturers and trainers have made ridiculously misleading claims about trivial programming stuff. One of their lecturers insisted that the second return in "return; return;" was probably needed just in case the first one did not work:

https://www.youtube.com/watch?v=_ZwiMlyeQNU&t=15s

In short, kids with little to no programming experience teach other disorientated desperate kids with few career opportunities in a country with a primitive economy.

Re:How to properly use macros in C by weberc2 on Sunday December 10, 2017 @05:05PM (#15893739)
> just in case the first one did not work

I repeat all statements in my code for exactly this reason. Sometimes I even compile the same code twice. You can never be too careful.

Re:How to properly use macros in C by flavio81 on Sunday December 10, 2017 @05:04PM (#15893733)
>One of their lecturers insisted that the second return in "return; return;"

That guy has a great career ahead in comedy!

Re:How to properly use macros in C by Stratoscope on Sunday December 10, 2017 @05:13PM (#15893771)
Well, I'm sorry, but I agree with the lecturer. I've run into this problem myself.

In my case I had some cleanup code to run at the end of the function in an error case, so I used "goto fail;" instead of "return;". And then just to be sure it always worked, I put in the "goto fail;" twice!

Re:How to properly use macros in C by mkroman on Sunday December 10, 2017 @05:17PM (#15893792)
Spotted the Apple developer!
Re:How to properly use macros in C by tzahola on Sunday December 10, 2017 @06:04PM (#15893980)
Gave me a good chuckle.
Re:How to properly use macros in C by flukus on Monday December 11, 2017 @12:53AM (#15895396)
> The claim that macros do not exist in other languages is incorrect

Technically incorrect, but how many of the top 20 languages (https://www.tiobe.com/tiobe-index/) have c style macros? I don't think many of them have a pre-processor at all.

Re:How to properly use macros in C by cjensen on Monday December 11, 2017 @02:00PM (#15899353)
At least 20% of those languages have macros (the three C-derived languages and Assembly). You don't need to have a pre-processor to have macros.

Some of those languages, like Python and C#, have advanced features which eliminate much of the need for macros. Others, like JavaScript and SQL, would be much improved by assembly-language or Lisp style macros.