Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Implicit int to enum
Implicit int to enum [message #1796157] Sun, 07 October 2018 13:28 Go to next message
Eclipse UserFriend
Hi,

I am building Unit Tests with Eclipse Luna as C projects. The files to be tested are compiled with a different embedded compiler. Eclipse uses the GCC C compiler.

I got the problem that the original files use implicit typecasts from integer to enum and I am looking for a way that Eclipse also use implicit typecasts. E.g. :
Code: [Select all] [Show/ hide]Rufus MapQuest UpToDate

typedef enum
{
e0 = 0U,
e1 = 1U,
e2 = 2U
} Enumtype;
void function(void)
{
int i=1;
Enumtype foo = i;
}


error I9167: argument of type "unsigned int" is incompatible with parameter of type "Enumtype"

The solution I found is:
Enumtype foo = (Enumtype) i;

However, this solution is unsatisfying in this case. I already checked the code analysis settings but I didn't found the option. Is there a way to enable these implicit casts?

[Updated on: Sun, 07 October 2018 19:38] by Moderator

Report message to a moderator

Re: Implicit int to enum [message #1796166 is a reply to message #1796157] Sun, 07 October 2018 18:51 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
I did not find an as ancient version of Eclipse as Luna. Using Photon on Kubuntu 18.04LTS Linux with GCC version 7.3.0 the following compiled and run without a hitch:

--- clip clip ---

#include <stdio.h>
#include <stdlib.h>

typedef enum
{
e0 = 0U,
e1 = 1U,
e2 = 2U
} Enumtype;


int main(void)
{
int i = 1;
Enumtype foo = i;

printf("hello, %u", foo);
return EXIT_SUCCESS;
}

--- clip clip ---

Your error message looks strange: there's nothing like it in CDT or GCC. Are you sure that you're not attempting to use e.g. some Windows C compiler?



--

Tauno Voipio
Re: Implicit int to enum [message #1796180 is a reply to message #1796166] Mon, 08 October 2018 04:24 Go to previous message
Marc-André Laperle is currently offline Marc-André LaperleFriend
Messages: 256
Registered: July 2009
Senior Member
There is nothing like that in CDT as far as I know so the error must be coming from the compiler (as Tauno suggested) or perhaps some other plugin you have installed.
Previous Topic:"Binary debug data entries"?
Next Topic:CDT does not detect Visual Studio paths in provider
Goto Forum:
  


Current Time: Wed Apr 24 21:09:56 GMT 2024

Powered by FUDForum. Page generated in 0.02611 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top