Author Topic: c/c++ No reference to #define when preceded by #ifndef  (Read 350 times)

LarryB

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
c/c++ No reference to #define when preceded by #ifndef
« on: February 06, 2018, 05:34:53 pm »
Can anyone explain why SlickEdit does not recognize the #define below with the preceding #ifndef?  If I change the #ifndef to a #ifdef it works fine -
#ifndef U_STRING_DECL_OPT
#define U_STRING_DECL_OPT(ustring, string, len) \
        /* original string array declare replaced with a pointer    @RW2A   \
        UChar ustring[len] may need to restore for Unicode          @RW2C */\
        UChar *ustring = string
#endif


Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2332
  • Hero Points: 308
Re: c/c++ No reference to #define when preceded by #ifndef
« Reply #1 on: February 06, 2018, 07:11:20 pm »
This worked correctly for me with 22.0.1.  What version/platform are you on?

Have you defined the "U_STRING_DECL_OPT" macro in your C/C++ Preprocessing configuration?  (Document > C/C++ Options... > C/C++ Preprocessing)  If so, what you are seeing would make sense, because the code inside the #ifndef would be skipped by our tagging and color coding (basically treated as a comment).

LarryB

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
Re: c/c++ No reference to #define when preceded by #ifndef
« Reply #2 on: February 06, 2018, 07:36:41 pm »
I am also running with 22.0.1.  I did not previously have the macro defined in the Preprocessing configuration, but added it hoping it would fix my issue.  It did not (and agrees with what you are saying).  So are you saying that if I delete the U_STRING_DECL_OPT macro in the Preprocessing config it should work? I deleted it, and SlickEdit went into an immediate retag all, and it is now resolved.  This is how I had it when I started. I'm grateful, but would still want to know why it is working now, when this is how it was when I started.

LarryB

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
Re: c/c++ No reference to #define when preceded by #ifndef
« Reply #3 on: February 06, 2018, 08:40:45 pm »
Okay, I am not totally happy with how it is now.  While SlickEdit now recognizes the macro USTRING_DECL_OPT it is not processing the macro -
#ifndef U_STRING_DECL_OPT
#define U_STRING_DECL_OPT(ustring, string, len) \
        /* original string array declare replaced with a pointer    @RW2A   \
        UChar ustring[len] may need to restore for Unicode          @RW2C */\
        UChar *ustring = string
#endif
-- when looking at the code that uses it:
   U_STRING_DECL_OPT(UEmptyString, "", 2); //U
   UEmptyString = "";           // not codepage dependent                 @B37C
The variable UEmptyString is not be resolved. (showing up in red)
The only time the variable was resolved was when I had the macro defined to the preprocessor and changed the #ifndef to an #ifdef.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2332
  • Hero Points: 308
Re: c/c++ No reference to #define when preceded by #ifndef
« Reply #4 on: February 07, 2018, 03:49:40 pm »
You will have to define the macro in the C/C++ Preprocessing options for it to be expanded.  And yes, that will make the definition of the macro within the #ifndef section be treated as inactive code (like a comment).  You won't see the reference in the #define, but you will see the reference in the #ifndef, so that gets you close enough.

In our next patch to SlickEdit (22.0.2), we are adding functionality to automatically pick up #define preprocessing within the current file.  However, this probably will not help you, as I imagine that the #define is in a header file, and the use is in another module, so defining it in the C/C++ Preprocessing options is your best bet.