Skip to content
SciTools Blog
Menu
  • Home
  • Blog
  • Support
  • Contact
  • Login
  • Pricing
  • Free Trial
Menu

Understanding Macro Heavy Code

Posted on September 17, 2021

Why read this?
It’s tough to make sense of code full of MACROs. Here is a solution to see your code with the MACROs replaced.

I have recently worked with many open-source projects, which made it evident that developers love using macros. How did I deal with it?

MACROS can make it difficult to read code. For example, here is an extract of LwIP:

We are going to create some “magic” to easily lets you see any code where MACROS’ definitions are replaced by their content, something like this:

How to?

1st, Most Important: Make sure you have the “Save Macro Expansion Set” checked in the project setup.
It’s under Project >> Configure Project >> C++ >> Options.

2nd, create a file named RemoveMacro.pl with the following PERL code:

use Understand;
die “Must be run from within Understand” if !Understand::Gui::active();
die “Must be run with a db open” if !Understand::Gui::db();
my $db = Understand::Gui::db();
my $filename = Understand::Gui::filename();
my $fileent = $db->lookup($filename,”File”);
if ($fileent) {
my $lexer = $fileent->lexer(1,8,1,1);
foreach my $lexeme ($lexer->lexemes()) {
my $lexeme_text = $lexeme->text();
printf($lexeme_text);
}}

3rd, Once you have created the script, Follow this 2-minute video’s instructions to set it up in your Understand Environment as a “User Tool”.

Note: (from Ken)

Another way to see macro definitions in Understand is to hover over a macro name anywhere you see it. Understand will show you its definition at that point in the code.

This is just one at a time, so it’s not as readable in total as the expand in source approach described in this article. I’m just adding it for completeness.

  • Instagram
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Learn more about Understand's Features

  • Dependency Graph
    View Dependency Graphs
  • Comply with Standards
  • View Useful Metrics
  • Team Annotations
  • Browse Depenedencies
  • Edit and Refactor

Related

Leave a Reply Cancel reply

You must be logged in to post a comment.

  • API
  • Architectures
  • Business
  • Code Comparison
  • Code Comprehension
  • Code Navigation
  • Code Visualization
  • Coding Standards
  • Dependencies
  • Developer Notes
  • DevOps
  • Getting Started
  • Legacy Code
  • Licensing
  • Metrics
  • Platform
  • Plugins
  • Power User Tips
  • Programming Practices
  • Uncategorized
  • Useful Scripts
  • User Stories
  • May 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • April 2023
  • January 2023
  • December 2022
  • November 2022
  • September 2022
  • August 2022
  • May 2022
  • April 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

©2025 SciTools Blog | Design: Newspaperly WordPress Theme