rlcarr@athena.mit.edu (Rich Carreiro) (03/09/89)
[followups to .tech]
I discovered this problem today. I have also sent this to a BBS [hence the
line numbers] and am too lazy to strip out the line numbers.
1: When using CPR on the following code, I get an interesting
2: inconsistency. I compiled it with:
3: lc -v -d2 -Lvma tst.c or
4: lc -v -d2 -ff -Lvfa tst.c
5:
6: The code is:
7: /*** tst.c ***/
8: #include <stdlib.h>
9: #include <stdio.h>
10: #include <math.h>
11:
12: void main()
13: {
14: int a,b;
15: float f;
16: double d;
17:
18: f = (float)3.3;
19: d = 3.3;
20:
21: a=sizeof(f);
22: b=sizeof(d);
23: }
24:
25: When I compile and link against lcm.lib, CPR says f is a float, and d is
26: a double. Also, CPR says a is 4 and d is 8. WHen I say that CPR says f
27: is a float and d is a double, I mean that when I do 'wha f', I get:
28: auto at xxxxxxx (4 bytes)
29: float
30:
31: and when I do 'wha d' I get:
32: auto at xxxxxxx (8 bytes)
33: double
34:
35: That all is nice and logical. However, when I compile with
36: lc -v -d2 -ff -Lvfa tst.c, the following happens:
37: A 'wha f' gives:
38: auto at xxxxxxx (8 bytes)
39: double
40:
41: and a 'wha d' gives:
42: auto at xxxxxxx (8 bytes)
43: double
44:
45: Meanwhile, 'd a' says a=4 and 'd b' says b=4. Who's confused, hte
46: compiler or CPR. I discovered this problem when trying to use
47: scanf() with lcmffp.lib. I had something like
48:
49: float f;
50: scanf("%f",&f);
51: and when I looked at f after the scanf(), it was wrong.
52: I tried using %hf and %lf as well, to no avail.
53:
54: Can anyone out there explain this, and can someone give me a definitive
55: answer on when to use %f, %lf, and %hf and with which floating point
56: libs.
57:
58: Thank you,
59: Rich
ARPA: rlcarr@athena.mit.edu
UUCP: ...!mit-eddie!mit-athena!rlcarr
BITNET: rlcarr%athena.mit.edu@MITVMA.mit.edu
*******************************************************************************
* Rich Carreiro "Back off man, I'm a scientist." *
* rlcarr@athena.mit.edu - Dr. Peter Venkman *
*******************************************************************************