Author Topic: color of code got wrong when using C preprocessor  (Read 2949 times)

wangsitan

  • Community Member
  • Posts: 15
  • Hero Points: 1
color of code got wrong when using C preprocessor
« on: October 27, 2014, 03:19:42 AM »
I got code like this:
Code: [Select]
int func(int a)
{
#if 0
if(0==a)
foo();
else
#endif
if(1==a)
bar();
}

According to my color setting, lines between "#if 0" and "#endif" should be grayed, and other lines should be multi-colored. Colors of code maybe correct when I was typing. But, if I open a file including those code, colors will go wrong: lines after "#endif" will be grayed, too. If I indent or unindent of the line "endif", the result will be sometimes OK and sometimes not.

There's no bug if I use preprocessor with no indent. But I think the code above is correct/legal because compiler (GCC 4.7.2) recognizes it.

SE version: v18.0.1.2 (hotfix revision: 33), Linux x86_64

Thanks.
« Last Edit: October 27, 2014, 03:29:00 AM by wangsitan »

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: color of code got wrong when using C preprocessor
« Reply #1 on: October 27, 2014, 11:36:54 PM »
I can't reproduce this problem with the sample code provided.

A few things to keep in mind:

1) There is a nesting limit for the preprocessor inactive code coloring.  So, if your preprocessing is nested over seven levels deep, you can expect the results to be less predictable.

2) SlickEdit pre-configures a lot of common preprocessing macros for you.  Maybe something at a higher level is preprocessing out the block you are working with.

Code: [Select]
int func(int a)
{
   #if 1
      #if XXXX1
      #if XXXX2
      #if XXXX3
      #if XXXX4
      #if __WIN32__

      #if 0
       if(0==a)
        foo();
       else
      #endif
      if(1==a)
         bar();

      #endif
      #endif
      #endif
      #endif
      #endif
   #endif
}

3) If you have a complete header file that exhibits a problem like this, it is very easy to obfuscate it so that you can post the sample file here.  From the SlickEdit command line just do this:
Code: [Select]
c/[a-z]/z/rXkpc

wangsitan

  • Community Member
  • Posts: 15
  • Hero Points: 1
Re: color of code got wrong when using C preprocessor
« Reply #2 on: October 30, 2014, 03:07:25 PM »
Hi, Dennis
Thanks for you reply.

I can reproduce this problem with that sample code (no other code in the C source file) on my office computer (Linux-64). But I cannot reproduce it on my home PC (WinXP-32).

Version of SlickEdit on two OS are same (both are 18.0.1.2 and hotfix 33).

I don't know how to deal with it.