|
|
View previous topic :: View next topic |
Author |
Message |
Torello
Joined: 29 Sep 2006 Posts: 120
|
V5051 enum (typecast) problems? |
Posted: Thu Dec 03, 2015 3:39 am |
|
|
Hi,
Compiling same source with v5051 instead of v5048 raises warnings:
"Assignment to enum is not of the correct type". Ok, I am assigning an int8 variable to a Enum variable. Never got any warning for that. But now, as code snippet below shows, the warning are there, but not very consistent.
-note: Function Com_FlashDataTx(int16) returns int8
Any thoughts?
Code: |
Enum ExitCodeType {zi_Ok=0, zi_AcqErr=1, zi_AcqTO=2, zi_PwrLo=3, zi_RstCpu=4, zi_Done=5,
zi_InfiniteSleep=6, zi_UserStore=7, zi_CmdTO=8, zi_ReJoin=9, zi_OORnge=10,
Zi_Fault=11, zi_GpsDM=12};
ExitCodeType ExitCode;
...
ExitCode = com_FlashDataTx(w1); //-> raises warning
ExitCode = com_FlashDataTx(0); //-> no warning
ExitCode = com_FlashDataTx(65000); //->no warning
ExitCode = 1; //->no warning
ExitCode = j; //->raises warning (int8 j;)
ExitCode = (ExitCodeType)j; //->raises warning
|
_________________ Regards, Edwin. PCWHD v5.114 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Dec 03, 2015 3:46 am |
|
|
It's a warning.
A poster here explicitly asked for this to be added. It does draw attention to the fact that you are assigning to an enum, and not using it's names to do so.
Just disable this warning, or ignore it. |
|
|
Torello
Joined: 29 Sep 2006 Posts: 120
|
|
Posted: Thu Dec 03, 2015 3:48 am |
|
|
Quick (dirty?) solution:
- declare ExitCode not as EXitCodeType but as int8
Thus:
int8 ExitCode _________________ Regards, Edwin. PCWHD v5.114 |
|
|
Torello
Joined: 29 Sep 2006 Posts: 120
|
|
Posted: Thu Dec 03, 2015 3:50 am |
|
|
Hi Ttelmah,
I can understand this, but the warning is not consistent.
Al least all 5 of the given assignments should then give this warning.
Assignment 6 should be OK, if an enum typecast is allowed in C _________________ Regards, Edwin. PCWHD v5.114 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Dec 03, 2015 4:02 am |
|
|
The problem may be that you actually have not declared an ExitCodeType properly. You have declared an enum type, but are then using this as if it is a type (it isn't). I'm surprised the compiler doesn't complain about this.
Code: |
enum ExitCodeType {zi_Ok=0, zi_AcqErr=1, zi_AcqTO=2, zi_PwrLo=3, zi_RstCpu=4, zi_Done=5,
zi_InfiniteSleep=6, zi_UserStore=7, zi_CmdTO=8, zi_ReJoin=9, zi_OORnge=10,
Zi_Fault=11, zi_GpsDM=12};
//The enumeration type at this point is defined as 'enum ExitCodeType'
//should technically be used as:
enum ExitCodeType ExitCode;
...
ExitCode = com_FlashDataTx(w1); //-> raises warning
ExitCode = com_FlashDataTx(0); //-> no warning
ExitCode = com_FlashDataTx(65000); //->no warning
ExitCode = 1; //->no warning
ExitCode = j; //->raises warning (int8 j;)
ExitCode = (enum ExitCodeType)j; //->raises warning
|
I suspect you will then find the warnings consistent....
To generate a type, it should instead be done with a Typedef:
Code: |
typedef enum {zi_Ok=0, zi_AcqErr=1, zi_AcqTO=2, zi_PwrLo=3, zi_RstCpu=4, zi_Done=5,
zi_InfiniteSleep=6, zi_UserStore=7, zi_CmdTO=8, zi_ReJoin=9, zi_OORnge=10,
Zi_Fault=11, zi_GpsDM=12} ExitCodeType;
ExitCodeType ExitCode;
...
ExitCode = com_FlashDataTx(w1); //-> raises warning
ExitCode = com_FlashDataTx(0); //-> no warning
ExitCode = com_FlashDataTx(65000); //->no warning
ExitCode = 1; //->no warning
ExitCode = j; //->raises warning (int8 j;)
ExitCode = (ExitCodeType)j; //->raises warning
|
So the reason the warnings are inconsistent, is the compiler is confused by the declarations. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|