Article View: comp.os.msdos.programmer
Article #1980Re: Unsigned long question
From: D'Arcy J.M. Cain
Date: Thu, 23 Aug 1990 16:35
Date: Thu, 23 Aug 1990 16:35
48 lines
1956 bytes
1956 bytes
In article <1990Aug20.163914.20063@sj.ate.slb.com> poffen@sj.ate.slb.com (Russ Poffenberger) writes:
>In article <5633@uwm.edu> peter@csd4.csd.uwm.edu (Peter J Diaz de Leon) writes:
>>I am having problems with the following simple piece of code.
>>When reg1 is an unsigned int mode prints out correctly.
>>When reg1 is an unsigned long int mode prints out
>>incorrect results. I have tried both Turbo C 2.0
>>
>>#include <stdio.h>
>>#define ME 0x12
>>
>>test(reg1, mode)
>>unsigned long reg1;
>>int mode;
>>{
>> printf("TEST: mode=0x%x \n", mode);
>> return;
>>}
>>main()
>>{
>> test(0x1, ME);
>> return;
>>}
>Ah yes, the infamous incompatible arguments problem. On most PC compilers,
>long and ints are not the same size. (int 16 bits, longs 32 bits). By default,
>
>To fix it, you must do one of two things..
>
>1.) Typecast to a long, for a constant, this is not the best practice.
>
>2.) Specify the constant as being long by appending 'l' to it. ie
Or do the "right" (tm) thing and use ANSI prototypes:
test(unsigned long reg1, int mode)
{
printf("TEST: mode=0x%x \n", mode);
return;
}
Since the function precedes the call to it, it effectively becomes a
prototype for itself and the promotion is automatically made. Also
a good idea if terms like "Data Abstraction" mean anything to you.
--
D'Arcy J.M. Cain (darcy@druid) |
D'Arcy Cain Consulting | MS-DOS: The Andrew Dice Clay
West Hill, Ontario, Canada | of operating systems.
+ 416 281 6094 |
Technical Details
Message-ID:
<1990Aug23.163557.25793@druid.uucp>Path:
arc1-ca.pugleaf.net!utzoo!telly!druid!darcyReferences:
<5633@uwm.edu> <1990Aug20.163914.20063@sj.ate.slb.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!utzoo!telly!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Subject: Re: Unsigned long question Message-ID: <1990Aug23.163557.25793@druid.uucp> Organization: D'Arcy Cain Consulting, West Hill, Ontario References: <5633@uwm.edu> <1990Aug20.163914.20063@sj.ate.slb.com> Distribution: usa Date: Thu, 23 Aug 90 16:35:57 GMT