Bug 219299 - Outline sort of struct fields
Summary: Outline sort of struct fields
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-18 05:48 EST by Romano Paolo Tenca CLA
Modified: 2020-09-04 15:19 EDT (History)
2 users (show)

See Also:


Attachments
proposed patch (853 bytes, patch)
2010-09-17 02:18 EDT, Patrick Hofer CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Romano Paolo Tenca CLA 2008-02-18 05:48:10 EST
Build ID: M20071023-1652

When Outline sort is enabled, fields of struct are sorted. It should not happen or an user option should permit to enable/disable sorting.
Comment 1 Patrick Hofer CLA 2010-09-17 02:17:33 EDT
The sorting itself is an easy fix. Can we change it as default or do we need some preferences? Any thoughts on this?
Comment 2 Patrick Hofer CLA 2010-09-17 02:18:36 EDT
Created attachment 179083 [details]
proposed patch
Comment 3 Markus Schorn CLA 2010-09-28 06:07:41 EDT
I don't see why fields should not be sorted, I would consider it a bug if they were not sorted. Can you explain?
Comment 4 Romano Paolo Tenca CLA 2010-09-28 14:01:47 EDT
I want to see offset or at least position of fields in a struct.
Comment 5 Patrick Hofer CLA 2010-09-28 14:58:21 EDT
I am wearing my C programmer hut on this topic. I definitely agree that fields in a C++ classes should not get sorted at all. Have to figure out how this can accomplished while addressing this bug as well. But going back to plain C for the explanation after one side-note.

To avoid the bug issue, and the corresponding bug-reports, I raised the question about preferences.

So back to low-level C "hacking" now. When a C programmer fiddles with structs he/she might just take the base address and manually add some offset to get to the field (e.g. when serializing things over some sort of serial line). Good luck for them with respecting all the padding.

Good coding style, probable not, but a fairly common pattern AFAIK. I've been asked why CDT changed the order and gets some users confused by co-workers. (at least once, if I remember correctly). They simply forgot that they "asked" CDT to do an alphabetically sorting

If you do such style of programming and and try to figure out the offset by having a look at outline, your will definitely have fun when you have the sorting enabled, and forgot about it.

Having said that, I have no particular problem if you decide to mark this bug as Fixed/Invalid. Although I would be interested in a comment of the original reporter of this bug.
Comment 6 Patrick Hofer CLA 2010-09-28 15:07:39 EDT
Thanks Romano. I hope I got your idea right.
Comment 7 Markus Schorn CLA 2010-09-29 03:27:26 EDT
(In reply to comment #4)
> I want to see offset or at least position of fields in a struct.

Certainly in c- or c++ programs the order of declaration is important (not only for fields). However, for faster navigation, it makes sense to present entities sorted by their name.
You have the choice between sorting the outline view and not sorting it. It is a bit odd to ask for a combination of both. 
If implemented (I prefer not to do that), this can only be a some sort of preference (e.g. "Never sort fields in the Outline View").
Comment 8 Patrick Hofer CLA 2010-09-29 03:47:34 EDT
Yes, it is a bit odd. Nevertheless I think I would use it some times.

Having thought about it again I agree that preferences are mandatory.

I'm thinking about to go the extra mile and add the preference. Any chance to get it in?

Shall I post a question to CDT-Dev to get more opinions?
Comment 9 Markus Schorn CLA 2010-09-29 04:06:57 EDT
(In reply to comment #8)
> Yes, it is a bit odd. Nevertheless I think I would use it some times.
> Having thought about it again I agree that preferences are mandatory.
> I'm thinking about to go the extra mile and add the preference. Any chance to
> get it in?
> Shall I post a question to CDT-Dev to get more opinions?
You can do that. Toni, what do you think?
Comment 10 Anton Leherbauer CLA 2010-09-29 04:33:11 EDT
(In reply to comment #9)
> (In reply to comment #8)
> > Yes, it is a bit odd. Nevertheless I think I would use it some times.
> > Having thought about it again I agree that preferences are mandatory.
> > I'm thinking about to go the extra mile and add the preference. Any chance to
> > get it in?
> > Shall I post a question to CDT-Dev to get more opinions?
> You can do that. Toni, what do you think?

Please ask on cdt-dev for some votes on this bug.  If there is enough interest, we can think about adding the feature.  In this case I would suggest to add the option as a drop down menu to the toolbar button instead of hiding it somewhere in a preference page.
Comment 11 Romano Paolo Tenca CLA 2010-09-29 13:27:49 EDT
Patrick Hofer i agree with you at all. I want also to remember that initialization of C struct can be done with this syntax:

struct s { void *b; int a;};

struct s mys = {NULL, 0};

where order is important.
Comment 12 Patrick Hofer CLA 2010-09-29 18:09:56 EDT
(In reply to comment #10)
> Please ask on cdt-dev for some votes on this bug.  

Will do as soon as time is permitting.

Romano, can you take this task?
Comment 13 Patrick Hofer CLA 2010-09-29 18:22:47 EDT
(In reply to comment #10)
> ...
>  In this case I would suggest to add the
> option as a drop down menu to the toolbar button instead of hiding it somewhere
> in a preference page.

Good point. It's nice to have as direct access as possible. Nevertheless the prefs should get involved because I might want to share my prefs with co-workers via export preferences.