Author Topic: Code Sense for unnamed struct/union fields  (Read 11565 times)

Offline nightlight

  • Multiple posting newcomer
  • *
  • Posts: 21
Code Sense for unnamed struct/union fields
« on: October 04, 2010, 02:50:58 am »
With stuct/union containing unnamed fields of struct/union type, the CodeSense doesn't display the field names inside these unnamed fields. For example

typedef struct _test {
  int a;
  union {
    int b;
    int c;
    };
  int d;
} TEST;

int main()
{
   TEST xx;
     xx.a=1;
     xx.b=3;   
     ...
}

When "xx." above is typed, CodeSense shows all fields of TEST except for fields 'b' and 'c' which are inside unnamed union (these fields have to have unique names within the structure i.e. one cannot have 'a' or 'd' inside the 'union' above). The VS CodeSense shows all fields, including 'b' and 'c'. It would be much more useful if C::B were to show all fields as well.

{ I am using only the regular release 10.5 of C::B and I don't know whether this was fixed within current nightly buids.}

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Sense for unnamed struct/union fields
« Reply #1 on: October 04, 2010, 03:59:32 am »
With stuct/union containing unnamed fields of struct/union type, the CodeSense doesn't display the field names inside these unnamed fields. For example

typedef struct _test {
  int a;
  union {
    int b;
    int c;
    };
  int d;
} TEST;

int main()
{
   TEST xx;
     xx.a=1;
     xx.b=3;   
     ...
}

When "xx." above is typed, CodeSense shows all fields of TEST except for fields 'b' and 'c' which are inside unnamed union (these fields have to have unique names within the structure i.e. one cannot have 'a' or 'd' inside the 'union' above).

The VS CodeSense shows all fields, including 'b' and 'c'. It would be much more useful if C::B were to show all fields as well.


The same in cc_branch.

Did you mean that
Code
xx.a
xx.b
xx.c
xx.d

all the above should be auto prompted?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nightlight

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Code Sense for unnamed struct/union fields
« Reply #2 on: October 04, 2010, 05:17:58 am »
all the above should be auto prompted?

That's how VS does it and it is quite useful. Unlike the named fields, for unnamed fields there is no other way to see those fields in the prompt, short of going back to the declaration in some other file.

BTW, C::B is a great IDE, very well thought out. I had to switch recently to a wider cross platform development (from previously only switching between Windows/VS & MAC/Xcode to include Linux now) and having tried all the IDE tools out there, C::B was the most pleasant and most natural among the alternatives.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Sense for unnamed struct/union fields
« Reply #3 on: October 04, 2010, 05:26:30 am »
all the above should be auto prompted?

This can be fixed.
Currently, there are three items shown when you press the dot

1, a
2, d
3, an UNnamedXXX union.

So, the third entry can be expanded to b,c.

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nightlight

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Code Sense for unnamed struct/union fields
« Reply #4 on: October 04, 2010, 05:42:23 am »
So, the third entry can be expanded to b,c.

Yes, but then the CodeSense inserts as the field name the string UnnamedUnionXXX.b into the code, rather than just b.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Sense for unnamed struct/union fields
« Reply #5 on: October 04, 2010, 05:44:20 am »
Yes, but then the CodeSense inserts as the field name the string UnnamedUnionXXX.b into the code, rather than just b.
I mean I can put it in my to-do list and implement this feature.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nightlight

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Code Sense for unnamed struct/union fields
« Reply #6 on: October 04, 2010, 05:49:36 am »
That would be great. If it comes into the nightly builds, please let me know. I will install it and test it right away, since I use the unnamed unions quite a bit (e.g. for args to a common API entry with many different functions behind).

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Sense for unnamed struct/union fields
« Reply #7 on: October 04, 2010, 01:23:16 pm »
Done, see the screenshot



But more test will be done before the patch released. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Code Sense for unnamed struct/union fields
« Reply #8 on: October 04, 2010, 05:01:30 pm »
like this code, shoud be fixed too.
Code
#include <iostream>

using namespace std;

class A
{
public:
    struct
    {
        int a;
        int b;
    };

    int c;
};

int main()
{
    A a;
    a.a = 1;
    a.b = 2;
    a.c = 3;
    cout << a.a << a.b << a.c << endl;
    return 0;
}

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Sense for unnamed struct/union fields
« Reply #9 on: October 04, 2010, 05:07:10 pm »
like this code, shoud be fixed too.
Code
#include <iostream>

using namespace std;

class A
{
public:
    struct
    {
        int a;
        int b;
    };

    int c;
};

int main()
{
    A a;
    a.a = 1;
    a.b = 2;
    a.c = 3;
    cout << a.a << a.b << a.c << endl;
    return 0;
}

it's sleep time now :D, I will fix this tomorrow.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nightlight

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Code Sense for unnamed struct/union fields
« Reply #10 on: October 04, 2010, 08:35:03 pm »
But more test will be done before the patch released. :D

Is it going to be in the nightly releases or as a patch to the distribution?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Code Sense for unnamed struct/union fields
« Reply #11 on: October 04, 2010, 08:38:21 pm »
But more test will be done before the patch released. :D

Is it going to be in the nightly releases or as a patch to the distribution?
Nightly of codecompletion-refactoring branch.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Sense for unnamed struct/union fields
« Reply #12 on: October 05, 2010, 07:38:33 am »
should be fixed in rev 6669 of cc_branch.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.