News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Displaying code inside of preprocessor's if/endif

Started by Beesdeckar, January 30, 2025, 11:23:03 AM

Previous topic - Next topic

Beesdeckar

Hello,
I have project type "custom Makefile" and I have C code inside of preprocessor #ifdef VAR ... #endif
and this code is displayed normally only when I #define VAR is above block in the same file.
When #define VAR is in some include file or I use Project build options -> custom variables, code editor ignores it and displays it in shadow colors.

I know that it can be set different colors for "inactive" code, but I'd like to have it functional due to better orientation when doing static code analysis.
Is is bug or is it by design ? Does exist some workaround for it ?

christo

@Beesdeckar I too use custom makefile projects a lot, and #ifdefs has been very annoying. If you can build from source, I just tried following workaround to view compiler settings for custom makefile projects, and it worked for me.

diff --git a/src/plugins/compilergcc/compileroptionsdlg.cpp b/src/plugins/compilergcc/compileroptionsdlg.cpp
index 069d72649..947ea16f5 100644
--- a/src/plugins/compilergcc/compileroptionsdlg.cpp
+++ b/src/plugins/compilergcc/compileroptionsdlg.cpp
@@ -433,8 +433,6 @@ CompilerOptionsDlg::CompilerOptionsDlg(wxWindow* parent, CompilerGCC* compiler,
     {
         nb->RemovePage(2); // remove "Search directories" page
         nb->RemovePage(1); // remove "Linker settings" page
-        nb->RemovePage(0); // remove "Compiler settings" page
-        XRCCTRL(*this, "tabCompiler", wxPanel)->Show(false);
         XRCCTRL(*this, "tabLinker", wxPanel)->Show(false);
         XRCCTRL(*this, "tabDirs", wxPanel)->Show(false);
     }


With this, Compiler settings are enabled in Project -> Build options..
Add defines in #defines tab
Save  project, close and open it again, and code under the #define looks normal.

christo

Better, if you can edit the project file to add the defines as follows under <Project> , it works, no need to modify codeblocks.

                <Compiler>
                        <Add option="-DVAR" />
                </Compiler>