Unsigned long question

Karl Heuer karl at haddock.ima.isc.com
Thu Aug 9 08:43:00 AEST 1990


In article <5631 at uwm.edu> peter at csd4.csd.uwm.edu (Peter J Diaz de Leon) writes:
>When reg1 is an unsigned int mode prints out correctly.
>When reg1 is an unsigned long int [it fails].

>	test(reg1, mode) unsigned long reg1; int mode; {
>	    printf("TEST: mode=0x%x \n", mode);
>	}
>	... test(0x1, ME);

The formal parameter has type `unsigned long int', but the actual argument
`0x1' has type `int'.  If you have lint, it should have flagged the mismatch.

The portable fix is to use an explicit cast:
	... test((unsigned long int)0x1, ME);
If you're only interested in ANSI C compilers, then you could use a typed
constant
	... test(0x1UL, ME);
or make sure there's a prototype in scope when test() is called:
	test(unsigned long reg1, int mode) {
	    printf("TEST: mode=0x%x \n", mode);
	}
	... test(0x1, ME);

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.lang.c mailing list