CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

V5051 enum (typecast) problems?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

V5051 enum (typecast) problems?
PostPosted: Thu Dec 03, 2015 3:39 am     Reply with quote

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: 19520

View user's profile Send private message

PostPosted: Thu Dec 03, 2015 3:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 03, 2015 3:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 03, 2015 3:50 am     Reply with quote

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: 19520

View user's profile Send private message

PostPosted: Thu Dec 03, 2015 4:02 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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