Author Topic: Nested struct type...  (Read 387 times)

joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Nested struct type...
« on: October 06, 2017, 05:48:11 pm »
When I reference the type of a nested struct, SlickEdit highlights it as unknown (symbol not found)...

for example, from outside the outer struct, when I reference the type of struct fwdt (which is defined within struct qla_hw_data), see screenshot image below...

Code: [Select]
struct qla_hw_data {
        uint some;
uint other;
        struct fwdt {
void *template;
ulong length;
ulong dump_size;
} fwdt[2];
 };
« Last Edit: October 06, 2017, 06:46:56 pm by joecar »

joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Re: Nested struct type...
« Reply #1 on: October 06, 2017, 05:58:35 pm »
Also, observation, if you look at the object fwdt of type struct fwdt, only some occurrences of it are highlighted as unknown, and the other occurrences are ok (not highlighted).
« Last Edit: October 06, 2017, 06:20:17 pm by joecar »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2213
  • Hero Points: 275
Re: Nested struct type...
« Reply #2 on: October 06, 2017, 09:03:58 pm »
I'll look into this.  It certainly makes the problem harder naming the variable the same name as the struct.

joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Re: Nested struct type...
« Reply #3 on: October 06, 2017, 10:53:23 pm »
I'll look into this.  It certainly makes the problem harder naming the variable the same name as the struct.
It happens regardless of the variables' name... just rename it to xxxx.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3951
  • Hero Points: 256
Re: Nested struct type...
« Reply #4 on: October 07, 2017, 12:40:47 pm »
Here's a simplified sample:

Code: [Select]
struct outer {
    int some;
    int other;
    struct inner {
        void *templat;
        long length;
        long dump_size;
    } fwdt[2];
};

void main(int argc, char *argv[]) {
    struct outer::inner a1; // This compiles
    struct inner a2; // This doesn't compile
}

I hope I'm following what's going on here. Am I?

Here's the error I get compiling this with the Microsoft 2015 compiler:
Code: [Select]
sample.cpp(13): error C2079: 'a2' uses undefined struct 'main::inner'


joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Re: Nested struct type...
« Reply #5 on: October 07, 2017, 08:25:54 pm »
Yes, the nested structs (inner, outer) are correct.

I'm not using C++

I'm using GNU C, and it compiles ok.


Declaring the inner struct does not shield it from being visible outside the outer struct.



« Last Edit: October 07, 2017, 08:41:38 pm by joecar »

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3951
  • Hero Points: 256
Re: Nested struct type...
« Reply #6 on: October 07, 2017, 09:16:35 pm »
I never realized that C treats this totally differently.

joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Re: Nested struct type...
« Reply #7 on: October 08, 2017, 10:51:05 pm »
lol, yes, there are some of us old C-only hacks still around  ;D

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2213
  • Hero Points: 275
Re: Nested struct type...
« Reply #8 on: October 09, 2017, 08:47:51 pm »
I wasn't aware of this C thing either.  I think I just threw up a little too...

The fix may to go into the point release since it is not hot-fixable.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2213
  • Hero Points: 275
Re: Nested struct type...
« Reply #9 on: October 09, 2017, 11:43:55 pm »
Update:  This will be fixed in the next release candidate.

joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Re: Nested struct type...
« Reply #10 on: October 10, 2017, 05:42:46 pm »
Also, not related to nested structs, how do you handle objects declared with typeof()...?

For example, see variable xyz in this pic, vs is highlighting it as unknown symbol:

« Last Edit: October 10, 2017, 06:04:38 pm by joecar »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2213
  • Hero Points: 275
Re: Nested struct type...
« Reply #11 on: October 10, 2017, 10:06:22 pm »
From what I gather, that is a GNU C extension, but I can add support for it.

joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Re: Nested struct type...
« Reply #12 on: October 10, 2017, 11:22:23 pm »
ok, thanks; yes, it is a gcc extension.
« Last Edit: October 10, 2017, 11:24:31 pm by joecar »

joecar

  • Senior Community Member
  • Posts: 137
  • Hero Points: 3
  • engineer/gearhead
Re: Nested struct type...
« Reply #13 on: October 10, 2017, 11:51:18 pm »
I have a more complex example, if you're interested...

Code: [Select]
static struct qla27xx_fwdt_entry *
qla27xx_fwdt_entry_other(struct scsi_qla_host *vha,
    struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
{
qla27xx_skip_entry(ent, buf);

return qla27xx_next_entry(ent);
}

static struct {
uint type;
typeof(qla27xx_fwdt_entry_other)(*call);
} qla27xx_fwdt_entry_call[] = {
{ ENTRY_TYPE_TMP_END , qla27xx_fwdt_entry_t255  } ,
{ ENTRY_TYPE_RD_IOB_T1 , qla27xx_fwdt_entry_t256  } ,
{ ENTRY_TYPE_WR_IOB_T1 , qla27xx_fwdt_entry_t257  } ,
{ ENTRY_TYPE_RD_IOB_T2 , qla27xx_fwdt_entry_t258  } ,
{ -1 , qla27xx_fwdt_entry_other }
};

static inline
typeof(*qla27xx_fwdt_entry_call->call)(*qla27xx_find_entry(uint type))
{
typeof(*qla27xx_fwdt_entry_call) *list = qla27xx_fwdt_entry_call;

while (list->type < type)
list++;

if (list->type == type)
return list->call;

return qla27xx_fwdt_entry_other;
}

static void
qla27xx_walk_template(struct scsi_qla_host *vha,
    struct qla27xx_fwdt_template *tmp, void *buf, ulong *len)
{
struct qla27xx_fwdt_entry *ent = (void *)tmp + le32_to_cpu(tmp->entry_offset);
ulong count = le32_to_cpu(tmp->entry_count);

while (count--) {
ulong type = le32_to_cpu(ent->hdr.type);
ent = qla27xx_find_entry(type)(vha, ent, buf, len);
if (!ent)
break;
}
}
I chopped out some of the code that was not relevant, but this still compiles ok (using gnu c).



edit: also see 2nd image for minor variation (typeof is already a pointer to function).
« Last Edit: October 11, 2017, 09:32:23 pm by joecar »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2213
  • Hero Points: 275
Re: Nested struct type...
« Reply #14 on: October 11, 2017, 12:06:38 am »
Yeah, not a really simple case, so that would require more work.  I'll file a future feature request for this case.

You can make the code a bit more readable and we handle it better if you do something like this.

Code: [Select]
typedef typeof(*qla27xx_fwdt_entry_call->call) typeof_qla27_yadda_yadda;
static inline typeof_qla27_yadda_yadda qla27xx_find_entry(uint type)