|
|
View previous topic :: View next topic |
Author |
Message |
epitalon Guest
|
int32 variable multiplied by 32 |
Posted: Thu Dec 03, 2009 11:07 am |
|
|
Hello,
I got a problem with compiler version v4.085
Code: |
void my_fct (unsigned int volume)
{
unsigned int32 volume_32;
volume_32 = (unsigned int32) volume * 32;
printf ("value : %Lu\r\n", volume_32);
volume_32 = 32 * (unsigned int32) volume;
printf ("value : %Lu\r\n", volume_32);
volume_32 = (int32) 32 * volume;
printf ("value : %Lu\r\n", volume_32);
}
|
Output of the above code (when "volume" is 200)
value : 6400
value : 0
value : 0
This is obviously a bug from the compiler. This is the fifth bug or more I find in the different versions of PCWH compiler, in a period of 4 years.
For the V4.085 only, this is the second one and I am stuck with a version that seems to be incomplete regarding the USB-hid example code.
Only my license has expired for nearly 9 months. I am stuck. Do you think that CCS will consider that I deserve a new release for free ?
That would be nice.
Recently, I bought the Intel C compiler, a very comprehensive suite for about $400 and some months later, Intel released a version that fixed some bugs and they urged all their customer by email to update for free their compiler !!!
What would be nice from CCS is that they allow me access to a known stable version of their compiler.
Jean-Marie Epitalon |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 03, 2009 1:48 pm |
|
|
I made your routine into the test program shown below and ran it in
the MPLAB simulator with several versions of the compiler. I used
UART1 to display the results in the Output window. Here's what I got:
PCH 3.249:
value : 6400
value : 6400
value : 6400
PCH 4.068:
value : 6400
value : 320
value : 256
PCH 4.086 (next version after your version)
value : 6400
value : 0
value : 0
PCH 4.099
value : 6400
value : 0
value : 0
PCH 4.100
value : 6400
value : 320
value : 256
PCH 4.101
value : 6400
value : 320
value : 256
Test program:
Code: |
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void my_fct (unsigned int volume)
{
unsigned int32 volume_32;
volume_32 = (unsigned int32) volume * 32;
printf ("value : %Lu\r\n", volume_32);
volume_32 = 32 * (unsigned int32) volume;
printf ("value : %Lu\r\n", volume_32);
volume_32 = (int32) 32 * volume;
printf ("value : %Lu\r\n", volume_32);
}
//======================================
void main(void)
{
my_fct(200);
while(1);
} |
To make your version give the desired output, I changed the castings
to 'int16', as shown below. Then I got this output:
value : 6400
value : 6400
value : 6400
Code: |
void my_fct (unsigned int volume)
{
unsigned int32 volume_32;
volume_32 = (int16)volume * 32;
printf ("value : %Lu\r\n", volume_32);
volume_32 = 32 * (int16)volume;
printf ("value : %Lu\r\n", volume_32);
volume_32 = (int16)32 * volume;
printf ("value : %Lu\r\n", volume_32);
}
|
For background information, Ttelmah has written several comments
on the CCS type promotion philosophy in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=29749 |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 03, 2009 4:25 pm |
|
|
Interestingly, the result is correct (according to the C standard) with PIC24 and PCD.
The considerations about a CCS "type promotion philosophy" sound somewhat like searching a reasonable concept
behind a sloppy designed handling of implicit type conversions. If there's a concept behind it, why has it been
introduced with V4.0, giving up the good V3.0 practice and effectively ignoring clear C rules. (But keep harping on
"full ANSI C compliance" in other regards). In my opinion, it's one of many V4.0 accidents, unfortunately not repaired
til today.
Thanks to PCM programmer for documenting the version differences! |
|
|
epitalon Guest
|
|
Posted: Fri Dec 04, 2009 4:10 am |
|
|
Thanks for all your comments.
But I would like to know:
Is CCS likely to give me a new compiler version because I found some bugs ? Did they do that to anyone of you ? |
|
|
rkinchin Guest
|
|
Posted: Fri Dec 04, 2009 8:08 am |
|
|
Implicit type promotion is haphazard. It sometimes works and mostly doesn't.
I have had to spend near a week recasting ANSI 'C' into something that PCD would understand. I think this compiler has passed its sell by date, good for quick 8 bit applications but is far too buggy and non standard to be of use for complex 16bit applications. |
|
|
|
|
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
|