Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!hao!gatech!uflorida!codas!pdn!usfvax2!jc3b21!fgd3 From: fgd3@jc3b21.UUCP (Fabbian G. Dufoe) Newsgroups: comp.sys.amiga Subject: Re: Amiga programmer's hint $14 Message-ID: <319@jc3b21.UUCP> Date: 29 Feb 88 05:46:03 GMT References: <4230019@hpfclq.HP.COM> <340@sas.UUCP> <707@mcdsun.UUCP> Organization: St. Petersburg Jr. College, FL Lines: 31 Summary: Isn't converting a short to a pointer always unsafe? In article <707@mcdsun.UUCP>, fnf@mcdsun.UUCP writes: > In article <340@sas.UUCP> toebes@sas.UUCP (John Toebes) writes: > >Under 4.0 (which supports short integers) the compiler will complain with > >error 101 whenever you ... convert a 16 bit entity to a pointer *REGARDLESS > >OF ANY CAST* it will issue the error message. This will catch almost > > This really should be discussed on comp.lang.c, but I'd like to note that > traditionally, a cast has been used to tell the compiler that the > programmer really DOES understand what he is asking for, and what the > expected results will be. ... I could support generating a warning > message here, but NEVER an error ... Generally I would agree that a cast is the programmer's way of telling the compiler that he really understands what he is doing and wants to do it. However, pointers are a special case, I think. Trying to convert a 16 bit value to a pointer won't work if the memory pointed to has an address higher than FFFF. Since C doesn't let you control the actual memory addresses to which you might want to point you have no guarantee unless the machines doesn't have an address space larger than 64K. So it seems reasonable to me for the compiler to treat that as an error. Even if you write for a 64K machine (shudder) the goal of portability demands that you not cast shorts to pointers because it will break on any larger machines. Is there any way you can cast shorts to pointers in a way that won't break if you have enough memory? --Fabbian Dufoe 350 Ling-A-Mor Terrace South St. Petersburg, Florida 33705 813-823-2350 UUCP: ...gatech!codas!usfvax2!jc3b21!fgd3