Author Topic: Displaying code inside of preprocessor's if/endif  (Read 1021 times)

Offline Beesdeckar

  • Multiple posting newcomer
  • *
  • Posts: 14
Displaying code inside of preprocessor's if/endif
« on: January 30, 2025, 11:23:03 am »
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 ?

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Displaying code inside of preprocessor's if/endif
« Reply #1 on: January 30, 2025, 01:02:47 pm »
@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.
Code
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.

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Displaying code inside of preprocessor's if/endif
« Reply #2 on: January 30, 2025, 01:20:40 pm »
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>