[comp.bugs.misc] Hummm, Altos compiler bug/feature?

larry@macom1.UUCP (Larry Taborek) (08/02/89)

Ok guys and gals.

I have a Altos 586 computer running 3.1a version of Xenix.  In
using the standard compiler that comes with the development set,
I found that I can only do mathmatical operations on shorts and
integers.  Floats, longs and doubles do not work.  Example:

main()
{
   int a;
   long b;

   a=0;b=0;
   a++;
   printf("a = %d\n",a);
   a = a + 1;
   printf("a = %d\n",a);
   b++;
   printf("b = %d\n",b);
   b = b + 1;
   printf("b = %d\n",b);
}

When run returns:

a = 1
a = 2
b = 0
b = 0

By the way, by using the sizeof command, I find that shorts and
integers take 2 bytes, longs and floats take 4 bytes and doubles
take 8 bytes.

I have looked in the compiler options to find out if there are
any floating point options.  There arn't, or at least none
documented.  Now I figure that you HAVE to be able to do this, so
what am I doing wrong?

Larry
-- 
Larry Taborek	..!uunet!grebyn!macom1!larry	Centel Federal Systems
		larry@macom1.UUCP		11400 Commerce Park Drive
						Reston, VA 22091-1506
						703-758-7000

r4@cbnews.ATT.COM (richard.r.grady..jr) (08/02/89)

In article <4874@macom1.UUCP> larry@macom1.UUCP (Larry Taborek) writes:
| Ok guys and gals.
| 
| I have a Altos 586 computer running 3.1a version of Xenix.  In
| using the standard compiler that comes with the development set,
| I found that I can only do mathmatical operations on shorts and
| integers.  Floats, longs and doubles do not work.  Example:
| 
| main()
| {
|    int a;
|    long b;
| 
|    a=0;b=0;
|    a++;
|    printf("a = %d\n",a);
|    a = a + 1;
|    printf("a = %d\n",a);
|    b++;
|    printf("b = %d\n",b);
|    b = b + 1;
|    printf("b = %d\n",b);
| }
| 
| When run returns:
| 
| a = 1
| a = 2
| b = 0
| b = 0
| 
| By the way, by using the sizeof command, I find that shorts and
| integers take 2 bytes, longs and floats take 4 bytes and doubles
| take 8 bytes.

In your example above, you have to tell printf()
that the data argument b is long.
You do this by putting a letter "l" in the format specification:
           printf("b = %ld\n",b);
Otherwise, printf() expects a 2-byte quantity, and it takes the
first two (presumably, higher-order) bytes of the 4-byte long.
These 2 bytes would be 00H, and printf() outputs 0.

-------------------------------------------------------------------
Dick Grady              r_r_grady@att.com          ...!att!mvuxd!r4 

allbery@nc386.UUCP (Brandon S. Allbery) (08/07/89)

You're gonna have one heck of a hard time trying to get a fix for that....

++Brandon
-- 
Brandon S. Allbery, moderator of comp.sources.misc	     allbery@NCoast.ORG
uunet!hal.cwru.edu!ncoast!allbery		    ncoast!allbery@hal.cwru.edu
"Why do trans-atlantic transfers take so long?"
"Electrons don't swim very fast."  -john@minster.york.ac.uk and whh@PacBell.COM