User forums > Using Code::Blocks

Is there any way to view the expanded macro definition code using codeblocks?

(1/1)

wanggaoteng:
Hi, there is a question in my textbook:

--- Code: ---#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;
}

--- End code ---
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

Miguel Gimenez:
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

wanggaoteng:

--- Quote from: Miguel Gimenez on February 11, 2019, 09:47:34 am ---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

--- End quote ---
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.

Miguel Gimenez:
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).

wanggaoteng:

--- Quote from: Miguel Gimenez on February 11, 2019, 01:51:17 pm ---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).

--- End quote ---
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.

Navigation

[0] Message Index

Go to full version