View previous topic :: View next topic |
Author |
Message |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
Unexpected #type int=n sideffect with PCD/PCH/PCM |
Posted: Sun Dec 28, 2008 4:05 pm |
|
|
Hello,
with a #type int=n directive in effect, the unsigned keyword in the below variable definition is ignored and the compare never executed by PCD (Versions up to V4.084). Any explanations?
Code: | #type int=16
unsigned int16 dt;
if (++dt >= 1800*24)
dt = 0; |
Last edited by FvM on Mon Dec 29, 2008 1:22 am; edited 1 time in total |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Dec 28, 2008 4:26 pm |
|
|
Quote: | #type int=16
unsigned int16 dt;
if (++dt >= 1800*24)
dt = 0; |
Unless I am missing something #type int=16 should have no effect on a
direct int16 declaration.
As it is written in your example (++dt >= 1800*24) will never execute so
I assume there must be more code in there somewhere. I have PCWH
not PCD so I can't check this.
Have you tried to do some direct assignment experiments to see what
size dt really is? (i.e. dt = 40000 then display the result to confirm).
Try 32000, 33000, 65000 and 66000 to see the results.
. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 28, 2008 4:41 pm |
|
|
There isn't more code. It's not the specific int=n size, it's the simple existence of the #type int= statement, that causes the issue. And it's apparently specific to PCD. With this statement in effect, unsigned int16 is treated as int16, a signed keyword is also ignored then, b.t.w.
Code: | #include <24FJ128GA106.h>
#type int=16
unsigned int16 dt;
void main(void)
{
while (1)
{
if (++dt >= 1800*24)
dt = 0;
}
} |
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Dec 28, 2008 5:48 pm |
|
|
Interesting.... Although, FWIW int16 is the same as unsigned int16. The
default for integers is unsigned in CCS. See below from the CCS manual.
Quote: | Note: All types, except float, by default are
unsigned; however, may be preceded by unsigned or signed.
|
I'll try this in PCWH to see what happens...
EDIT UPDATE:
After doing some testing I found the same result in PCWH. Adding the line
#type int=16 makes all integers unsigned and overrides any signed
declarations. Simply commenting out this line returns everything to
normal. This may be as designed but I can't find it in the manual.
FVM, Are you going to report this to CCS?
. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Dec 29, 2008 1:12 am |
|
|
Thanks for your extended tests.
The difference is, that PCH has a default of unsigned for int types while PCD has a default of signed. I didn't remember this difference. In both cases, the #type int= statement invalidates the preceeding signed/unsigned of a variable definition. The below code template allows to test the different behaviour. In each case, an error message Variable of this data type is never greater than this constant indicates an ignorance of the signed/unsigned definition.
Code: | //#include <24FJ128GA106.h>
//#include <18F4620.h>
#include <16F688.h>
//#type signed
//#type signed
#type int=16
unsigned int16 dt=0;
signed int16 dts=0;
void main(void)
{
while (1)
{
if (++dt >= 1800*24)
dt = 0;
if (++dts < -1800*24)
dts = 0;
}
} |
Yes, I'll report this to CCS.
Best regards,
Frank |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Dec 29, 2008 7:51 am |
|
|
It's interesting that they changed the signed/unsigned default in PCD.
Also, I don't get the message "Variable of this data type is never greater than this constant" in PCWH.
This apparently was added only in PCD. Folks going from PCH to PCD are going to have fun with these differences!
I don't remember any significant issues of that sort at all gong from PCM to PCH (other than bug fixes).
Dave |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Dec 29, 2008 9:41 am |
|
|
The change to default signed int type in PCD is a move towards the C-standard, I think.
I get the said greater than this constant warning also with PCH, PCM and PCD, also the compiler removes the compare code in this case. So far the behaviour appears similar with all compiler variants. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Dec 30, 2008 1:11 am |
|
|
CCS support tells:
Quote: | The problem you reported has been fixed and will be in the
next compiler release. |
|
|
|
|