Author Topic: Nested struct definitions...  (Read 3659 times)

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Nested struct definitions...
« on: March 30, 2018, 04:49:42 PM »
Usage of a struct defined within another struct is still highlighting as unknown symbol...

For example:

Code: [Select]
struct hw {
. . .
struct fwdt {
void *template;
ulong length;
ulong dump_size;
} fwdt[2];
. . .
};

see usage of struct fwdt in attached pic (highlighted as unknown symbol);

struct fwdt is defined only within struct hw and not defined anywhere else.


(* notice multiple name spaces *)

I'm using GNU C (gcc).

SE version 22.0.2.1 64-bit with hotfix_se2202_3_cumulative.



« Last Edit: March 30, 2018, 05:06:50 PM by joecar »

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #1 on: March 30, 2018, 05:53:17 PM »
Here is another example:

Code: [Select]
struct qos_fcport_table {
uint16_t version;
. . .
struct qos_fcport_table_row {
uint8_t wwpn[8];
. . .
} table[];
} __packed;

struct qos_fcport_table_row  is defined within struct qos_fcport_table (not anywhere else)...

« Last Edit: March 30, 2018, 06:48:06 PM by joecar »

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #2 on: August 30, 2018, 05:01:16 PM »
Just to let you know that this still happens in v23.0.0.3

Screenshots of two instances attached (unknown symbols are in yellow highlight)

The definition of struct fwdt is embedded within another struct;
same with definitions of struct qos_fcport_table and struct qos_fcport_row, they are embedded within another struct.

I'm using GNU C.

The code compiles/runs ok.


« Last Edit: August 30, 2018, 06:17:57 PM by joecar »

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: Nested struct definitions...
« Reply #3 on: August 30, 2018, 10:42:57 PM »
I'll file a defect against this one.  This is a really ugly ANSI-C case, where you are using the same name in three different ways in close proximity.

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: Nested struct definitions...
« Reply #4 on: August 30, 2018, 10:47:10 PM »
Actually, not filing a defect report.  These examples work correctly, provided you are in ANSI-C mode.

Document > Select Mode > ANSI-C

Do this for all your ANSI-C or K&R C files, you might want to point the "c" and "h" extensions at ANSI-C.

Then rebuild your workspace tag file.
« Last Edit: August 30, 2018, 10:49:20 PM by Dennis »

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #5 on: September 06, 2018, 04:41:16 PM »
Ok, thanks, I will set doc mode to ANSI C.

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #6 on: September 06, 2018, 04:43:25 PM »
Is there a way to do this for the whole project/workspace, or all .c/.h files in bulk/batch...?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6866
  • Hero Points: 528
Re: Nested struct definitions...
« Reply #7 on: September 06, 2018, 05:51:41 PM »
If you have not already made .c and .h use ANSI-C instead of C/C++ mode do the following

* Close all your files.
* go to Tools>Options>Languages>Application Languages>ANSI-C>General.
* Click on the Edit These Extensions... button. Add c and h.

Now when you open .c and .h files, they should be in ANSI-C mode. There are ways this can fail but hopefully closing your open files first will help. Workspace auto-restore information (.vpwhist and .vpwhistu) stores the mode name (seems like we can improve this to only store it if it's been overridden). Also, perfile.xml in your config directory can store the mode name (it's smart about it).

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #8 on: September 07, 2018, 10:50:55 PM »
Ok, I'll try this, thanks.

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #9 on: October 09, 2018, 05:48:05 PM »
In Beta 6 the ANCI-C document type has disappeared.


Anyway, I tried what you said above (last month) with ANSI-C and it made no difference (still got/get unknown symbol highlighting) (I've now selected GNU C/C++);

however, when you do Goto Definition, it takes you to the correct place in the struct...

i.e. it is only the unknown symbol highlighting that is incorrect.


« Last Edit: October 09, 2018, 05:51:22 PM by joecar »

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: Nested struct definitions...
« Reply #10 on: October 09, 2018, 05:51:17 PM »
You are saying that ANSI-C is not in the list you go to Document > Select Mode... ?

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #11 on: October 09, 2018, 06:46:54 PM »
I went back and checked again, and now I see ANSI-C...  :-[  I don't what happened prior...? 

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #12 on: October 09, 2018, 07:02:24 PM »
Ok, I'm all better now...   ;D

I was able to set the document mode to ANSI-C (using Beta 6) for all source files, and now the unknown symbol highlighting is working properly (has gone away for nested structs)

( I had to retag the kernel include files so that those symbols would be defined )


Thanks, I appreciate all your help.

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: Nested struct definitions...
« Reply #13 on: October 09, 2018, 07:31:50 PM »
No problem, glad you have things in order now.  It is a shame that some C++ code adopted ".c" and ".h" as file extensions, so we can't simply treat them as ANSI-C by default.  But, given the trade-offs, it is much more compatible for us to treat them as C++ out of the box.

joecar

  • Senior Community Member
  • Posts: 424
  • Hero Points: 9
  • engineer/gearhead
Re: Nested struct definitions...
« Reply #14 on: October 10, 2018, 01:56:26 AM »
I understand.