[comp.sys.mac] LSC error in printf?

chris@umbc3.UUCP (03/23/87)

In article <306@umbc3.UMD.EDU>, scotty@umbc3.UMD.EDU (Scott Paisley) writes:
> 
> 	I was playing around with LSC 2.01 the other night and was
> having some fun with large integers.  Anyway the following program
> gives some interesting results...
> 
> #include <stdio.h>
> main()
> {
> 	long biggie = 0x7fffffff;
> 	printf("Biggie is 0x%x  0x%x\n", biggie, biggie);
> }
> 
.......chopped for brevity & reader's sake.........
> It appears that only half of the longword is getting printed with printf.
> (By doing successive printfs, we got the other half of the word - lord knows
>  why...)
> 
> What is going on here?  Is this a bug or undocumented feature?  :-)
> 
> -- 
> Scott Paisley	

Scotty,

At the bottom of page 51 in the manual update, you will find the solution
to your problem among many others.  To quote:

PROBLEM:  printf and scanf don't seem to work correctly with long or
          double data.

SOLUTION: 
   A common misconception about printf is that printf "knows" about its
arguements.  If you pass a long expression to printf, you must specify in
the format string that you want a long expression to be printed.  Example:

int anInt;
long aLong;
printf("long is %ld, int is %d\n", aLong, anInt);
___________________________

So there ya have it....put that lower-case "L" before the d.  I just
tried your program...in your case, it is acceptable to use the line:
printf("Biggie is 0x%lx\n", biggie);


-- 
ARPA   : chris@umbc3.UMD.EDU		BITNET : chris@umbc

"If all else fails, read the instructions!"