Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: R1S8K on May 15, 2021, 12:25:32 pm

Title: How to get the C generated code ?
Post by: R1S8K on May 15, 2021, 12:25:32 pm
Hi,

I'm using macros and having problem knowing how the code works. So one told me to use a flag that output the expanded generated code.

But I don't know how to use it in codeblocks.
Title: Re: How to get the C generated code ?
Post by: oBFusCATed on May 15, 2021, 12:31:43 pm
We don't have anything integrated for the task.
The easiest way is to do a build of the file, copy the command, modify it and run it in terminal.
If you do this often you can set up a tool for it.

Here are some hints about the flags needed: https://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines
Title: Re: How to get the C generated code ?
Post by: R1S8K on May 15, 2021, 12:38:57 pm
Sorry I forgot to mention that I use Windows 10.

Quote
The easiest way is to do a build of the file, copy the command, modify it and run it in terminal.

Can this  be done in Windows ?
Title: Re: How to get the C generated code ?
Post by: oBFusCATed on May 15, 2021, 04:28:09 pm
Yes. The principles and operation is the same on all OSes (mostly).
Title: Re: How to get the C generated code ?
Post by: BlueHazzard on May 17, 2021, 01:17:14 am
Quick, easy and dirty you can add the -E flag in Project->Build options->Compiler settings->other compiler options

If you hit compile now, the generated object file (with the file ending .o in PROJECT_FOLDER/obj/BUILD_TARGET_NAME/SOURCE_FILE_NAME.o) will contain the preprocessed source. You can open it with any text editor you like. Linking will fail obviously. To compile the program again you have to remove the -E flag and make a rebuild: Build->Rebuild