Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: wanggaoteng on February 11, 2019, 09:14:48 am

Title: Is there any way to view the expanded macro definition code using codeblocks?
Post by: wanggaoteng on February 11, 2019, 09:14:48 am
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;
}
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
Title: Re: Is there any way to view the expanded macro definition code using codeblocks?
Post by: 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 (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
Title: Re: Is there any way to view the expanded macro definition code using codeblocks?
Post by: wanggaoteng on February 11, 2019, 01:25:08 pm
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 (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.
Title: Re: Is there any way to view the expanded macro definition code using codeblocks?
Post by: 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).
Title: Re: Is there any way to view the expanded macro definition code using codeblocks?
Post by: wanggaoteng on February 11, 2019, 04:37:34 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).
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.