Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 285126

Summary: Showing the actual (int) value of an enum variable in CDT editor on hover
Product: [Tools] CDT Reporter: Steffen Schmidt <steffen-schmidt>
Component: cdt-editorAssignee: Paulo Garcia <pgarcia>
Status: RESOLVED FIXED QA Contact: Ken Ryall <ken.ryall>
Severity: enhancement    
Priority: P3 CC: cdtdoug, dirk.janssen, eclipse.sprigogin, iceonfire014, inductiveload, malaperle, marc.khouzam, mohanhambar, pawel.1.piech, pgarcia, sie, yevshif, zeratul976
Version: 6.0   
Target Milestone: 8.6.0   
Hardware: All   
OS: All   
Whiteboard:

Description Steffen Schmidt CLA 2009-07-30 04:42:54 EDT
When using enumerations instead of #defines for constants in C/C++ code it is sometimes necessary to be able to view the enum variables current value in integer format instead of its symbolic enumeration value. This can be achieved by casting the enum variable in Variables or Expressions view to (int).
It would be very helpful to directly be able to get the enum integer value by hovering over the enum variable in the CDT C/C++ editor.
Comment 1 Anton Leherbauer CLA 2009-08-18 02:59:16 EDT
This would be a debug feature.
Comment 2 Dirk Janssen CLA 2013-03-18 12:57:26 EDT
I disagree with this being a sole debug feature.
Rather, I see it as an editor feature which does not depend on debug mode.
It is indeed useful if you can hover the mouse over an enum symbol and see its actual value.
Visual Studio does it nicely.
In Eclipse, all I get is the repeated plain enum symbol in the hover.
Comment 3 Simon Raybould CLA 2013-06-07 06:19:20 EDT
This is not a "debug feature"!, this is an editor feature and it's missing in eclipse.
This feature is standard in other intelligent source code editors such as Visual Studio and Source Insight. Both of these editors show the integer value of an enum by simply hovering over the symbolic name with the mouse. This functionality is not provided by the debugger (Source Insight doesn't contain a debugger!, it's just an editor).
The values are constants so the software does not need to be running for this to work. In fact this is a very useful feature during development of code that may not even compile at that stage.
Comment 4 Paulo Garcia CLA 2014-08-13 14:33:19 EDT
I wonder if this is not already included in the latest CDT 8.4...

For example, if I have something like:

enum {
   FIRST = 33,
   SECOND,
   THIRD
};

int main(void) {
  (...)
  if (num == FIRST) {
      ....
  }
}

I can see that FIRST if 33 when hovering the mouse over it in the if statement.

Is this feature this bug is asking about?
Comment 5 Yevgeny Shifrin CLA 2014-08-13 15:30:11 EDT
(In reply to Paulo Garcia from comment #4)
> I wonder if this is not already included in the latest CDT 8.4...
> 
> For example, if I have something like:
> 
> enum {
>    FIRST = 33,
>    SECOND,
>    THIRD
> };
> 
> int main(void) {
>   (...)
>   if (num == FIRST) {
>       ....
>   }
> }
> 
> I can see that FIRST if 33 when hovering the mouse over it in the if
> statement.
> 
> Is this feature this bug is asking about?

When hovering mouse over THIRD does it show 35?
Comment 6 Paulo Garcia CLA 2014-08-13 15:48:01 EDT
> When hovering mouse over THIRD does it show 35?

Oh ok, I see the problem now. It doesn't show the value for other enums other than the first. Thanks
Comment 7 Paulo Garcia CLA 2014-08-17 15:18:30 EDT
Fix sent to gerrit for review:

https://git.eclipse.org/r/31807
Comment 9 ice fire CLA 2015-02-10 15:08:59 EST
Paulo, is this update merged into the main CDT branch? I've tried using the latest version of Eclipse Keplar and Luna and when hovering over "THIRD" in the example below, it only shows the enum name "THIRD". When hovering over FIRST, it does display FIRST = 33.

enum {
   FIRST = 33,
   SECOND,
   THIRD
};

int main(void) {
  (...)
  if (num == FIRST) {
      ....
  }
}
Comment 10 Sergey Prigogin CLA 2015-02-10 15:17:49 EST
(In reply to ice fire from comment #9)
> Paulo, is this update merged into the main CDT branch?

See comment #8.

You should be using https://hudson.eclipse.org/cdt/job/cdt-8.6/lastSuccessfulBuild/artifact/releng/org.eclipse.cdt.repo/target/org.eclipse.cdt.repo.zip
Comment 11 ice fire CLA 2015-02-11 16:22:29 EST
Thanks Sergey that worked! The link you gave me contains a .zip file with artifacts.jar and content.jar which allowed me to install it in my eclipse through "Install New Software" and adding it as an archive. 

However, in comment #8, the link (http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=3bfe2d21a74cacf0bc45d83e805c95fe727f4543) shows a link to download a different .zip file which I could not install.

---
download	org.eclipse.cdt-3bfe2d21a74cacf0bc45d83e805c95fe727f4543.zip
---

Did I miss the link on that page somehow or is there another way to install this commit with this direct .zip file?
Comment 12 Nathan Ridge CLA 2015-02-11 16:39:08 EST
(In reply to ice fire from comment #11)
> However, in comment #8, the link
> (http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/
> ?id=3bfe2d21a74cacf0bc45d83e805c95fe727f4543) shows a link to download a
> different .zip file which I could not install.

That zip contains a snapshot of the source code at the time of the commit. You'd need to build it before you can install it.

Building from source is described here [1], but if you're not planning on doing development on CDT itself, you're probably better off just downloading a nightly build from Hudson, such as the one Sergey linked to.

[1] https://wiki.eclipse.org/Getting_started_with_CDT_development
Comment 13 ice fire CLA 2015-02-11 16:42:47 EST
(In reply to Nathan Ridge from comment #12)
> (In reply to ice fire from comment #11)
> > However, in comment #8, the link
> > (http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/
> > ?id=3bfe2d21a74cacf0bc45d83e805c95fe727f4543) shows a link to download a
> > different .zip file which I could not install.
> 
> That zip contains a snapshot of the source code at the time of the commit.
> You'd need to build it before you can install it.
> 
> Building from source is described here [1], but if you're not planning on
> doing development on CDT itself, you're probably better off just downloading
> a nightly build from Hudson, such as the one Sergey linked to.
> 
> [1] https://wiki.eclipse.org/Getting_started_with_CDT_development

Understood :) Thank you all!