News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Code Sense for unnamed struct/union fields

Started by nightlight, October 04, 2010, 02:50:58 AM

Previous topic - Next topic

nightlight

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.}

ollydbg

Quote from: nightlight 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.


The same in cc_branch.

Did you mean that

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.

nightlight

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.

ollydbg

Quote from: nightlight on October 04, 2010, 05:17:58 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.

nightlight

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.

ollydbg

Quote from: nightlight on October 04, 2010, 05:42:23 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.

nightlight

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).

ollydbg

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.

Loaden

like this code, shoud be fixed too.
#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;
}

ollydbg

Quote from: Loaden on October 04, 2010, 05:01:30 PM
like this code, shoud be fixed too.
#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.

nightlight

Quote from: ollydbg on October 04, 2010, 01:23:16 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?

Jenna

Quote from: nightlight on October 04, 2010, 08:35:03 PM
Quote from: ollydbg on October 04, 2010, 01:23:16 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.

ollydbg

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.