Jump to content

Recommended Posts

Hello !

 

I have a strange result in the following code :

SeringueActive.VolumePar_Pas = 196385;
long Volume = 1000;
long inter11;
long inter12;

inter11 = Volume * 1000;
inter12 =	SeringueActive.VolumePar_Pas/1000;
NbrePas = inter11/inter12;
NbrePas = (Volume * 1000)/(SeringueActive.VolumePar_Pas/1000);

 

Variable SeringueActive.VolumePar_Pas type is unsigned char .

 

Result of the following line NbrePas = inter11/inter12; is 5102.

 

When the line NbrePas = (Volume * 1000)/(SeringueActive.VolumePar_Pas/1000); is executed NbrePas is 0 !!!

 

Where this unexpected result is coming from ?

 

Thanks you for your help,

Jean-Marie

Edited by schneiderj

Share this post


Link to post
Share on other sites

jean-M,

 

Confirm the size of SeringueActive.VolumePar_Pas. An unsigned char would give those results. You also haven't told us how NbrePas is declared.

Share this post


Link to post
Share on other sites

Hi !

 

Sorry for this, I try to write all declaration, but till some are missing :

 

Here is the declaration of those variables :

unsigned long NbrePas;

struct Seringue
{
unsigned char ID_Seringue; // 0 à 15
unsigned char Volume; // en mL
unsigned int DiametreInterne; // en µm
unsigned char LongueurUtile; // en mm
unsigned long VolumePar_Pas; // µm*mm^2 par pas
};
extern struct Seringue SeringueActive;

 

It seems that the problem occur with "SeringueActive.VolumePar_Pas/1000" : it's looks like the division is not done, and by the way a obtain a result lower than 1, and give null.

But I don't know how to verify this hypothesis.

 

 

Jean-Marie

Share this post


Link to post
Share on other sites

Hi Jean-Marie ,

 

The assembler code doesn't look too good for the

NbrePas = (Volume * 1000)/(SeringueActive.VolumePar_Pas/1000);

statement. The intermediate value from the multiplication is getting lost.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
so it's look like a bug...

 

Yes this looks like a bug. We'll investigate. Meanwhile please use a workaround: compile function that uses this expression with level 1 optimization (to do this put #pragma OPTIMIZE "1" just before the function).

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Yes this looks like a bug. We'll investigate. Meanwhile please use a workaround: compile function that uses this expression with level 1 optimization (to do this put #pragma OPTIMIZE "1" just before the function).

 

Regards,

Pavel

Ok, I will try this tomorrow when I back. I let you know the results.

 

Jean-Marie

Share this post


Link to post
Share on other sites
Ok, I will try this tomorrow when I back. I let you know the results.

 

Hello,

 

That done. And when I use this directive #pragma OPTIMIZE "1" there is no error.

I am impressed by your "intuition" !

 

Jean-Marie

Share this post


Link to post
Share on other sites

This bug has been fixed. It was caused by over-optimisation. The fix will be available in the next release.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...