Page 1 of 1

Bug in QL C - Lattice C?

Posted: Sat Jan 12, 2019 6:12 pm
by ohcan_ognara
Hello

After 30 years or more I've come back to QL playing with ancient QLC. I'm using the POW() function but it seems I've never been able to obtain correct results. This little program below returns 1.000000 whereas it should return 4.000000.

Is that a bug or do you thing I'm doing something wrong...

Thanks

Code: Select all

#include <mdv1_stdio_h>
#include <mdv1_math_h>

main()
{

	double ov2;

	ov2 = pow(2,2);
	printf("%f\n", ov2);

}

Re: Bug in QL C - Lattice C?

Posted: Sat Jan 12, 2019 7:14 pm
by XorA
try pow(2.0,2.0)

pow takes doubles as arguments and you've passed it ints, older compilers don't always promote correctly.

Re: Bug in QL C - Lattice C?

Posted: Sat Jan 12, 2019 7:49 pm
by NormanDunbar
What do you get if you do this instead?

Code: Select all

   ov2 = pow(2.0, 2.0);
Or

Code: Select all

   ov2 = pow((double)2.0, (double)2.0);

Cheers,
Norm.

Re: Bug in QL C - Lattice C?

Posted: Sat Jan 12, 2019 8:53 pm
by ohcan_ognara
Thanks Norm and XorA.

Indeed both solutions work. I was a little confused since the very same code worked on Lattice 3.04 (Atari ST). It seems as you stated correctly that Lattice 3.02 (QL) is not able to promote ints to doubles correctly.

Thank you guys!

Re: Bug in QL C - Lattice C?

Posted: Mon Jan 14, 2019 5:39 pm
by ql_freak
Warning: QLC (Lattice C 3.02) has one really horrible bug in stdio.h. When it returns EOF (which must be an int - that was always so, even in K&R C), it returns a char. As char is signed on the 68000, when the character code FF (decimal 255) exists in a file, it is sign extended and EOF (-1) is returned. This makes the stdio functions nearly unusable for binary data. BTW: The first versions of C68 have had the same bug.

Correct behaviour is: Return 0xFF (255) as an int (0x00FF) for the character code 0xFF and -1 as int (0xFFFF) for EOF.

BTW: For your example you should at least get a warning if you change it to:

Code: Select all

#include <mdv1_stdio_h>
#include <mdv1_math_h>

double pow(double, double); /* Lattice C supports function prototypes, albeit not ANSI-C compatible */

main()
{

   double ov2;

   ov2 = pow(2,2);
   printf("%f\n", ov2);

}