Macros in Programming Languages

The cluster discusses the use, advantages, disadvantages, and necessity of macros in languages like C, C++, Rust, and Elixir, debating their role in handling boilerplate, code generation, hygiene, and as alternatives to other language features.

➡️ Stable 0.5x Programming Languages
5,273
Comments
20
Years Active
5
Top Authors
#7177
Topic ID

Activity Over Time

2007
17
2008
37
2009
88
2010
98
2011
122
2012
137
2013
183
2014
273
2015
323
2016
318
2017
358
2018
305
2019
354
2020
472
2021
428
2022
442
2023
434
2024
414
2025
463
2026
9

Keywords

IMO JS DSL MIPS L491 C23 HTML CTFE github.com CL macros macro code templates compiler proc code generation cpp rust write

Sample Comments

empath75 Apr 3, 2019 View on HN

Seems like most languages where you'd use this already have macros?

tester756 Nov 6, 2025 View on HN

Macro is one of the ugliest features available in langs like C/CPP

kazinator Oct 13, 2021 View on HN

Macros don't appear in your code example, so they cannot solve anything.

Macros are inscrutable garbage and a sorry hack.

platz May 8, 2015 View on HN

using macros to deal with boilerplate, although useful, though is of a different order than things that simply cannot be expressed without macros

pharmakom Jun 7, 2022 View on HN

Most languages don’t have macros powerful enough to do this.

tarruda Jan 13, 2021 View on HN

Aren't macros a just form of code generation?

horlux Sep 1, 2022 View on HN

you can do that using macros in langs such as c, cpp or elixir

pjmlp Oct 17, 2022 View on HN

As if macros weren't their own kind of magic.

Periodic Jul 12, 2013 View on HN

Macros still can cause a lot of problems. See some of the crazy C++ macros or Template Haskell.