Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Unsigned long question Message-ID: <17296@haddock.ima.isc.com> Date: 8 Aug 90 22:43:00 GMT References: <5631@uwm.edu> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Distribution: usa Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 24 In article <5631@uwm.edu> peter@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@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint