ANSI scanf dropping sign bit?

martin at clubmed.hf.intel.com.ogi.edu martin at clubmed.hf.intel.com.ogi.edu
Thu Mar 8 02:02:12 AEST 1990


Why does the following program when linked to an ANSI standard library
produce the following:

input: 90000000

output: 10000000

input: 80000000

output: 00000000

#include <stdio.h>

int main()
{
	unsigned int	input;

	scanf("%x", &input);

	printf("%x\n", input);
}

It appears that sign bit is being dropped.  I have run this program on
Sys V.3.2 and it retains the sign bit, but this is not ANSI compliant.

Any hints...
thanks

                          
                  _/_          |
 ______  __.  __  /  o ____    |  textronix!reed!intelhf!clubmed!martin
/ / / <_(_/|_/ (_<__<_/ / <    |
                               |  martin at clubmed.hf.intel.com
                               |



More information about the Comp.lang.c mailing list