🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1945

Re: Unsigned long question

#1945
From: Russ Poffenberger
Date: Mon, 20 Aug 1990 16:39
57 lines
2085 bytes
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
>and Turbo C++ 1.0 and get the strange results. 
>Can somebody please explane to me what I am
>over looking.
>
>I am running on a Compaq Deskpro 286 using 
>4dos ver:3.01a and DOS ver:3.31
>
>	Thanks
>	-Peter
>	peter@csd4.csd.uwm.edu
>	peter@cvax.cs.uwm.edu
>
>=============================================================================
>
>#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,
constants are interpreted as ints. You are therefore attempting to pass an int
argument to a function that expects a long.

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


	test(0x1l,ME);


Russ Poffenberger               DOMAIN: poffen@sj.ate.slb.com
Schlumberger Technologies       UUCP:   {uunet,decwrl,amdahl}!sjsca4!poffen
1601 Technology Drive		CIS:	72401,276
San Jose, Ca. 95110             (408)437-5254
Technical Details
Message-ID: <1990Aug20.163914.20063@sj.ate.slb.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!mips!sjsca4!poffen
References: <5633@uwm.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!mips!sjsca4!poffen
From: poffen@sj.ate.slb.com (Russ Poffenberger)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Unsigned long question
Message-ID: <1990Aug20.163914.20063@sj.ate.slb.com>
Date: 20 Aug 90 16:39:14 GMT
References: <5633@uwm.edu>
Reply-To: poffen@sj.ate.slb.com (Russ Poffenberger)
Distribution: usa
Organization: Schlumberger Technologies, San Jose, CA.
Lines: 57