Author Topic: Is there any way to view the expanded macro definition code using codeblocks?  (Read 438 times)

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 28
Hi, there is a question in my textbook:
Code: [Select]
#include "stdio.h"

#define GENERIC_MAX(type)       \
type type##_max(type x,type y)  \
{                               \
    return x>y?x:y;             \
}

typedef unsigned long ULONG;

GENERIC_MAX(ULONG)

int main(void)
{
    printf("%ld\n",ULONG_max(2,4));
    return 0;
}
I want to view the expanded macro definition code of "GENERIC_MAX(ULONG)", how to do about it using codeblocks?
Best regards.
P.S. My codeblocks is codeblocks-17.12mingw-setup.exe
« Last Edit: February 11, 2019, 09:37:47 am by wanggaoteng »

Offline Miguel Gimenez

  • Regular
  • ***
  • Posts: 303
Google returns hundreds of links, try this:

https://stackoverflow.com/questions/3916979/how-do-i-run-the-gcc-preprocessor-to-get-the-code-after-macros-like-define-are

The -E option can be added in Project build settings -> Compiler settings -> Other compiler options
« Last Edit: February 11, 2019, 09:49:48 am by Miguel Gimenez »

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 28
Google returns hundreds of links, try this:

https://stackoverflow.com/questions/3916979/how-do-i-run-the-gcc-preprocessor-to-get-the-code-after-macros-like-define-are

The -E option can be added in Project build settings -> Compiler settings -> Other compiler options
Thank you. But there is a problem using codeblocks. I add -E to "settings -> Compiler settings -> Other compiler options", as the picture 1 illustrated, and click the "Build" button, an error appeared, as the picture 2 illustrated.
In "install\CodeBlocks\MinGW\bin", I open DOS, and input "gcc -E test.c >test.txt" in the command line, after push Enter key, then the test.txt contains the expanded macro definition code.
« Last Edit: February 11, 2019, 01:37:24 pm by wanggaoteng »

Offline Miguel Gimenez

  • Regular
  • ***
  • Posts: 303
The -E output breaks the automated building. You can try using the Tools+ plugin with command line "gcc -E $(ACTIVE_EDITOR_FILENAME)" (I have never used this plugin, so I can't help you here).

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 28
The -E output breaks the automated building. You can try using the Tools+ plugin with command line "gcc -E $(ACTIVE_EDITOR_FILENAME)" (I have never used this plugin, so I can't help you here).
It seems that "gcc -E test.c >test.txt" works very well for solving this question, although a little troublesome, it doesn't matter.
Thanks again.