Author Topic: Unknown symbol coloring for nested defined struct usage  (Read 702 times)

joecar

  • Senior Community Member
  • Posts: 251
  • Hero Points: 9
  • engineer/gearhead
Unknown symbol coloring for nested defined struct usage
« on: June 24, 2019, 06:43:15 pm »
SlickEdit v23.0.2.0 64-bit with hotfix_se2302_2_cumulative

See attached pic, shows unknown symbol coloring (yellow highlight) for struct's defined (named) in a nested manner;
this is the struct defining struct but and struct led:
Code: [Select]
// pwm button led abstraction
struct pwm {
struct {
uint32_t period, pulsewidth, tickend;
uint16_t brightness;
} cycle;
struct but {
struct led {
uint8_t port;
int16_t intensity, scale, offset;
uint32_t tickoff;
} led[3];
} but[5];
};

I'm using GCC.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2815
  • Hero Points: 426
Re: Unknown symbol coloring for nested defined struct usage
« Reply #1 on: June 24, 2019, 08:46:31 pm »
This is the same problem you reported last year.  The solution was for the header with the nested structs to be in ANSI-C mode, since it is ANSI-C, not C++.  "struct but" is not visible outside of "struct pwm" in C++, so the symbol coloring is correct to flag those as unknown symbols.

joecar

  • Senior Community Member
  • Posts: 251
  • Hero Points: 9
  • engineer/gearhead
Re: Unknown symbol coloring for nested defined struct usage
« Reply #2 on: June 24, 2019, 09:31:35 pm »
I thought I had selected ANSI-C, let me check, thanks.

joecar

  • Senior Community Member
  • Posts: 251
  • Hero Points: 9
  • engineer/gearhead
Re: Unknown symbol coloring for nested defined struct usage
« Reply #3 on: June 24, 2019, 09:42:51 pm »
I see... I had to associate .c and .h with ANSI-C rather than C/C++.

Thanks.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2815
  • Hero Points: 426
Re: Unknown symbol coloring for nested defined struct usage
« Reply #4 on: June 24, 2019, 09:52:10 pm »
Your example did lead me to find a couple bugs handling the same case written in C/C++ style, so I am checking a couple hot fixes for that.  They will not help your ANSI-C code case though.

Code: [Select]
// Using :: to qualify scope
static inline void pwm_led_start_next_cycle2(struct pwm *pwm) {
pwm->cycle.tickend = sys_ticks+pwm->cycle.period;
for (struct pwm::but *but = pwm->but; but<ARRAYEND(pwm->but); but++) {
for (struct pwm::but::led *led = but->led; led<ARRAYEND(but->led); but++) {
led->tickoff = sys_ticks+((pwm->cycle.pulsewidth*led->intensity)>>8);
         _led_set_state_(led, led->tickoff > sys_ticks);
}
}
}

Code: [Select]
// using "auto" to avoid naming types
static inline void pwm_led_start_next_cycle(struct pwm *pwm) {
pwm->cycle.tickend = sys_ticks+pwm->cycle.period;
for (auto *but = pwm->but; but<ARRAYEND(pwm->but); but++) {
for (auto *led = but->led; led<ARRAYEND(but->led); but++) {
led->tickoff = sys_ticks+((pwm->cycle.pulsewidth*led->intensity)>>8);
         _led_set_state_(led, led->tickoff > sys_ticks);
}
}
}

joecar

  • Senior Community Member
  • Posts: 251
  • Hero Points: 9
  • engineer/gearhead
Re: Unknown symbol coloring for nested defined struct usage
« Reply #5 on: June 24, 2019, 10:07:47 pm »
Is there a way to specify ANSI-C or C/C++ for the whole project (rather than for individual .c and .h files)...?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2815
  • Hero Points: 426
Re: Unknown symbol coloring for nested defined struct usage
« Reply #6 on: June 25, 2019, 02:00:29 pm »
Not in the project properties per-se, but you can use the advanced file mappings.  Tools > Options > Languages > Advanced File mappings.


joecar

  • Senior Community Member
  • Posts: 251
  • Hero Points: 9
  • engineer/gearhead
Re: Unknown symbol coloring for nested defined struct usage
« Reply #7 on: June 25, 2019, 06:46:02 pm »
Ok, thanks, I will try that.

GNU C is somewhere in-between ANSI-C and C++... how should I deal with GNU C...?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2815
  • Hero Points: 426
Re: Unknown symbol coloring for nested defined struct usage
« Reply #8 on: June 25, 2019, 07:16:16 pm »
We can't realistically deal with every combination of compiler extensions.  We try, but this particular case is inherently ambiguous, so we have to pick a direction:  ANSI-C mode does what it is supposed to do, C++ does what it is supposed to do.  You kind of have to assess the same choice and decide if you are writing C++ or ANSI-C, or non-standard code that you should expect to be problematic for other compilers and tools.  If it were my choice, I'd go the C++ direction and properly qualify the type names the way they are nested.

joecar

  • Senior Community Member
  • Posts: 251
  • Hero Points: 9
  • engineer/gearhead
Re: Unknown symbol coloring for nested defined struct usage
« Reply #9 on: June 25, 2019, 07:36:27 pm »
Ok, thanks.