The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

One cautionary thing with C programming: the cost of macro expansion

Posted by jpluimers on 2024/10/03

The result C macros having become more lenient on the types they expect, is that they can become very large expansions. This not only causes long expanded code lines, but also

This shows you some examples:

[Wayback/Archive] Lorenzo Stoakes on social.kernel.org: For those interested in the ‘combinatorial explosion of min()/max() macro’ thing slowing down kernel builds, witness the horrors :))

[Wayback/Archive] Re: [PATCH 0/7] minmax: reduce compilation time – Linus Torvalds

โ€ฆ

So it _looks_ like "pageblock_order", and it *acts* like a simple
compile-time constant, but our complex type-checking min() macro ends
up making it horrible.

โ€ฆ

so we have a single expansion that is 253kB in size. And it comes from this:

โ€ฆ

so once again it's "pageblock_order", it's just that it's now mixed in
with "max()".

โ€ฆ

which looks very tame indeed, but it turns out that
"bio_for_each_segment()" expands to 82kB of code.

โ€ฆ

The solution is relatively simple: introduce macros that are less relaxed about the parameters and be cautions using them. That’s what the above PATCH actually does,

--jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.