Newsgroups: alt.folklore.computers From: source@netcom.com (David Harmon) Subject: C implementation where (void *) and (char *) not the same Content-Type: text/plain; charset=us-ascii Message-ID: <3503a8bd.192554150@source.netcom.com> Sender: source@netcom14.netcom.com Content-Transfer-Encoding: 7bit Organization: Netcom On-Line Services X-Newsreader: Forte Agent 1.5/32.451 Mime-Version: 1.0 Date: Thu, 15 Jan 1998 06:18:23 GMT Lines: 4 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!leto.ou.edu!news.onenet.net!news-out.internetmci.com!newsfeed.internetmci.com!169.132.11.200!news.idt.net!newspeer.monmouth.com!ix.netcom.com!source Is there any real known implementation of C (or C++) where the internal representations of void pointers (void *) and other types of pointers such as character (char *) were not the same? What was it, and what caused the need for pointer representations to differ? ###### Newsgroups: alt.folklore.computers From: engebret@sg1.cr.usgs.gov (Chris Engebretson) Subject: Re: C implementation where (void *) and (char *) not the same X-Nntp-Posting-Host: sg1.cr.usgs.gov Message-ID: Sender: news@igsrsparc2.er.usgs.gov (Janet Walz (GD) x6739) Reply-To: engebret@sg1.cr.usgs.gov Organization: Raytheon STX Corporation References: <3503a8bd.192554150@source.netcom.com> Date: Thu, 15 Jan 1998 16:44:22 GMT Lines: 31 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!news.he.net!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!novia!sws1.ctd.ornl.gov!news.er.usgs.gov!sg1.cr.usgs.gov!engebret In article <3503a8bd.192554150@source.netcom.com>, source@netcom.com (David Harmon) writes: |> Is there any real known implementation of C (or C++) where the |> internal representations of void pointers (void *) and other types of |> pointers such as character (char *) were not the same? What was it, |> and what caused the need for pointer representations to differ? There are a few examples of machines that differentiate internally between the concept of a byte pointer and that of a word pointer, through different addressing notation/architectural representation. An example of this type of machine would be the HP 3000 series (the "Classic" architecture, which was replaced sometime in the 80's with a new "PA-RISC" style architecture, IIRC.) Under this type of approach, (char *) and (void *) are represented as byte pointers and everything else is typically a word pointer. The comp.lang.c FAQ mentions some other esoteric implementations with unusual pointer conventions (different types have different sizes, null pointers are not all-bits-zero, etc.) However, note that C89 requires that (void *) and (char *) not only have the same size, but the same representation (and furthermore that they have the least-strict alignment.) Regards, -- Chris Engebretson - Raytheon STX Corporation | Ph#: (605)594-6829 USGS EROS Data Center, Sioux Falls, SD 57198 | Fax: (605)594-6940 http://edcwww.cr.usgs.gov/ mailto:engebret@sg1.cr.usgs.gov Opinions are not those of Raytheon Systems Company or the USGS. ###### From: Robert Billing Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: Thu, 15 Jan 98 20:40:09 GMT Message-ID: <884896809snz@tnglwood.demon.co.uk> References: <3503a8bd.192554150@source.netcom.com> Reply-To: unclebob@tnglwood.demon.co.uk X-Mail2News-User: unclebob@tnglwood.demon.co.uk X-Mail2News-Path: post-10.mail.demon.net!post.mail.demon.net!tnglwood.demon.co.uk X-Trace: mail2news.demon.co.uk 884898226 25086 unclebob tnglwood.demon.co.uk X-Complaints-To: abuse@demon.net X-Newsreader: Demon Internet Simple News v1.29 Lines: 40 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!news-dc-3.sprintlink.net!news-dc-1.sprintlink.net!news-east.sprintlink.net!news-peer.sprintlink.net!news.sprintlink.net!Sprint!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!dispose.news.demon.net!demon!news.demon.co.uk!demon!mail2news.demon.co.uk!tnglwood.demon.co.uk!unclebob In article engebret@sg1.cr.usgs.gov "Chris Engebretson" writes: > Under this type of approach, (char *) and (void *) are represented > as byte pointers and everything else is typically a word pointer. > The comp.lang.c FAQ mentions some other esoteric implementations > with unusual pointer conventions (different types have different > sizes, null pointers are not all-bits-zero, etc.) As has been said on this group before, any implentation of C which does not have the null pointer zero is fundamentally broken. Even extreme machines such as the T8 transputer with a *signed* address bus manage to get this right. I dont't mind what the internal representation is, but to agree with the K & R books, casting a null pointer to integer must give zero. What is much more exciting is the TMS340 graphics engine, with bit addressable memory. It does the Right Thing, in that it complies with the standards, but char * P, * Q ; int R ; P = & Thing ; Q = P + 1 ; R = (int) Q - (int) P ; puts 8 in R, even though R = Q - P ; gives 1. This is strictly correct, but startling. -- I am Robert Billing, Christian, inventor, traveller, cook and animal lover, I live near 0:46W 51:22N. http://www.tnglwood.demon.co.uk/ "Bother," said Pooh, "Eeyore, ready two photon torpedoes and lock phasers on the Heffalump, Piglet, meet me in transporter room three" ###### From: sarr@engin.umich.edu (Sarr J. Blumson) Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 16 Jan 1998 15:26:34 GMT Organization: University of Michigan Lines: 19 Message-ID: <69nu7a$3tu$1@newbabylon.rs.itd.umich.edu> References: <3503a8bd.192554150@source.netcom.com> Reply-To: sarr@umich.edu NNTP-Posting-Host: sinshan.engin.umich.edu Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!news-xfer.siscom.net!streamer1.cleveland.iagnet.net!qual.net!iagnet.net!sunqbc.risq.qc.ca!newsxfer.itd.umich.edu!newbabylon.rs.itd.umich.edu!sarr In article , William J. Hayes wrote: >How about any word oriented machine without a "natural" char data type? >Early DEC alpha's, with 64 bit words and no 8 bit data type. Or perhaps >the PDP-12, 36 bit words,no other data type; roll your own char's, four >9 bit char's to the word, or five 7 bit char's. You mean the PDP (or DECsystem, if you prefer) 10 and 20. The C compiler we built at ADP stored (char *) as a character count from 0, so casting a char * to an int * involved a divide by 5. Made arithmetic quick, but dereferencing a char * required a divide and a table lookup to get the byte offset for the LoaDByte instruction. -- -------- Sarr Blumson sarr@umich.edu voice: +1 734 764 0253 home: +1 734 665 9591 ITD, University of Michigan http://www-personal.umich.edu/~sarr/ 535 W William, Ann Arbor, MI 48103-4943 ###### From: Malte.Uhl@neuss.netsurf.de (Malte Uhl) Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same References: <3503a8bd.192554150@source.netcom.com> <884896809snz@tnglwood.demon.co.uk> Message-ID: X-Newsreader: slrn (0.9.4.3 UNIX) NNTP-Posting-Host: netsurf51.neuss.netsurf.de Date: 16 Jan 98 19:47:26 GMT Organization: "ebner & martin informationssysteme gmbh" Lines: 10 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!news-dc-3.sprintlink.net!news-dc-1.sprintlink.net!news-east.sprintlink.net!news-peer.sprintlink.net!news.sprintlink.net!Sprint!newsfeed.nacamar.de!news-hh.maz.net!news.arkaden.net!Malte.Uhl In article <884896809snz@tnglwood.demon.co.uk>, Robert Billing wrote: >> sizes, null pointers are not all-bits-zero, etc.) > >representation is, but to agree with the K & R books, casting a null >pointer to integer must give zero. Where's the contradiction here? The compiler would be somewhat harder to built, agreed. Malte ###### From: seebs@plethora.net (Peter Seebach) Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 16 Jan 1998 20:58:19 GMT Organization: Plethora Internet Lines: 19 Message-ID: <69ohlb$pjm$1@darla.visi.com> References: <3503a8bd.192554150@source.netcom.com> NNTP-Posting-Host: herd.plethora.net NNTP-Posting-Date: 16 Jan 1998 14:58:19 CST X-Newsreader: trn 4.0-test60 (5 October 1997) Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!nntp.flash.net!Supernews60!supernews.com!news.maxwell.syr.edu!streamer1.cleveland.iagnet.net!qual.net!iagnet.net!209.98.98.14!visi.com!news-out.visi.com!not-for-mail In article <3503a8bd.192554150@source.netcom.com>, David Harmon wrote: >Is there any real known implementation of C (or C++) where the >internal representations of void pointers (void *) and other types of >pointers such as character (char *) were not the same? What was it, >and what caused the need for pointer representations to differ? No. The C standard requires that (char *) and (void *) have the same representation. There are probably several where, say, (char *), (int *), and (double *) are different. -s -- seebs@plethora.net -- I am not speaking for my employer. Copyright '97 All rights reserved. Boycott Spamazon! End Spam. C and Unix wizard - send mail for help, or send money for a consultation. Visit my new ISP --- More Net, Less Spam! Plethora . Net ###### From: seebs@plethora.net (Peter Seebach) Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 16 Jan 1998 20:59:49 GMT Organization: Plethora Internet Lines: 25 Message-ID: <69oho5$pjm$2@darla.visi.com> References: <3503a8bd.192554150@source.netcom.com> <884896809snz@tnglwood.demon.co.uk> NNTP-Posting-Host: herd.plethora.net NNTP-Posting-Date: 16 Jan 1998 14:59:49 CST X-Newsreader: trn 4.0-test60 (5 October 1997) Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!leto.ou.edu!hammer.uoregon.edu!logbridge.uoregon.edu!ais.net!visi.com!news-out.visi.com!not-for-mail In article <884896809snz@tnglwood.demon.co.uk>, Robert Billing wrote: > As has been said on this group before, any implentation of C which >does not have the null pointer zero is fundamentally broken. Even >extreme machines such as the T8 transputer with a *signed* address bus >manage to get this right. I dont't mind what the internal >representation is, but to agree with the K & R books, casting a null >pointer to integer must give zero. That's not required by the standard. It is required that converting an integer constant expression with the value zero to a pointer of any type give a null pointer; there is no guarantee that you even *CAN* convert a pointer of any sort to an integer, nor is there a guarantee of what you can get. The null pointer is "zero", that doesn't mean it has to have any (or all) *bits* zero. -s -- seebs@plethora.net -- I am not speaking for my employer. Copyright '97 All rights reserved. Boycott Spamazon! End Spam. C and Unix wizard - send mail for help, or send money for a consultation. Visit my new ISP --- More Net, Less Spam! Plethora . Net ###### From: dhollow@bnr.ca (Darren [D.] Holloway [BNR]) Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 16 Jan 1998 21:30:29 GMT Organization: Northern Telecom Wireless Development Center, Calgary Lines: 25 Distribution: world Message-ID: <69ojhl$rkd@bcrkh13.bnr.ca> References: <3503a8bd.192554150@source.netcom.com> <884896809snz@tnglwood.demon.co.uk> NNTP-Posting-Host: 47.120.64.134 Originator: holloway@nwdch124 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!atl-news-feed1.bbnplanet.com!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!newsxfer3.itd.umich.edu!newsxfer.itd.umich.edu!gumby!newspump.wustl.edu!biko.cc.rochester.edu!news.acsu.buffalo.edu!srv1.drenet.dnd.ca!crc-news.doc.ca!nott!bcarh189.bnr.ca!bmerhc5e.bnr.ca!bcrkh13.bnr.ca!holloway In article , Malte.Uhl@neuss.netsurf.de (Malte Uhl) writes: |> In article <884896809snz@tnglwood.demon.co.uk>, Robert Billing wrote: |> >> sizes, null pointers are not all-bits-zero, etc.) |> > |> >representation is, but to agree with the K & R books, casting a null |> >pointer to integer must give zero. Please quote chapter and verse to support this. 0 is defined to return 1 when compared to a null pointer in a pointer context. Casting a pointer to an int removes the pointer context and thus the value is implementation dependent. Read all of chapter 5 in the comp.lang.c FAQ for more info. Regards, -Darren the Obscure -- Darren G. Holloway Nortel WDC, Calgary Human Being, esq. dhollow@nortel.ca ESN 765-4859 "There's no problem you can't solve with duct tape and a makefile." --Tom Malaher, tmalaher@netstart.com ###### Path: ccw.ch!usenet From: Neil.Franklin.remove.this@ccw.ch Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 17 Jan 1998 03:11:49 +0100 Organization: My own Private Self Lines: 40 Message-ID: References: <3503a8bd.192554150@source.netcom.com> <884896809snz@tnglwood.demon.co.uk> X-Newsreader: Gnus v5.3/Emacs 19.34 In article engebret@sg1.cr.usgs.gov "Chris Engebretson" writes: > The comp.lang.c FAQ mentions some other esoteric implementations > with unusual pointer conventions (different types have different > sizes, null pointers are not all-bits-zero, etc.) Robert Billing added to this: > Even extreme machines such as the T8 transputer with a *signed* address > bus manage to get this right. I dont't mind what the internal > representation is, but to agree with the K & R books, casting a null > pointer to integer must give zero. Yes, the T800 (note the 3 digit number) and its predecessor T414. The most quirky chips I ever saw (one of each of them is laying 2 meters from here in a drawer). They needed signed adresses because they did not know about unsigned arithmetic and producing an sign overflow, which triggered an error condition (IIRC the processor got stopped). And on them (char *) and (int *) are different. All addresses were the amount of bytes or words relative to the stack pointer or the middle of memory (address 0 (!), yes null pointers point to here). The code: static int foo = 0x12345678; int * bar = *foo; char baz = * (char *) bar; /* 0x78, little endian */ actually generated an shift left by 2 on the typecast in line 4. That requires an unknown pointer to be flagged (void *), so that extra handling can be inserted to make it usable. -- Neil.Franklin.remove.this@ccw.ch, http://www.ccw.ch/Neil.Franklin/ for Geek Code, Papernet, Voicenet, PGP public key see http: Mac, 95 and NT users are CLUEless (Command Line User Environment) If I go missing, its once again my newsfeed that has craped ###### From: Robert Billing Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: Sat, 17 Jan 98 08:53:01 GMT Distribution: world Message-ID: <885027181snz@tnglwood.demon.co.uk> References: <3503a8bd.192554150@source.netcom.com> <884896809snz@tnglwood.demon.co.uk> <69ojhl$rkd@bcrkh13.bnr.ca> Reply-To: unclebob@tnglwood.demon.co.uk X-Mail2News-User: unclebob@tnglwood.demon.co.uk X-Mail2News-Path: post-20.mail.demon.net!post.mail.demon.net!tnglwood.demon.co.uk X-Trace: mail2news.demon.co.uk 885027307 21738 unclebob tnglwood.demon.co.uk X-Complaints-To: abuse@demon.net X-Newsreader: Demon Internet Simple News v1.29 Lines: 43 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!news-dc-3.sprintlink.net!news-dc-1.sprintlink.net!news-east.sprintlink.net!news-peer.sprintlink.net!news.sprintlink.net!Sprint!news-peer.gip.net!news.gsl.net!gip.net!news.idt.net!dispose.news.demon.net!demon!news.demon.co.uk!demon!mail2news.demon.co.uk!tnglwood.demon.co.uk!unclebob In article <69ojhl$rkd@bcrkh13.bnr.ca> dhollow@bnr.ca "Darren [D.] Holloway [BNR]" writes: > |> >representation is, but to agree with the K & R books, casting a null > |> >pointer to integer must give zero. > > Please quote chapter and verse to support this. P102 "Pointers and integers are not interchangable. Zero is the sole exception:..." I have always taken this to mean that zero is the exception to the general rule, and that zero pointers and integers are freely interchangable. However the sentence continues "...the constant zero may be assigned to a pointer, and a pointer may be compared with the constant zero." and this is where the problem lies. I have always taken the sentence to be constructed as follows. Generally true statement: two examples. However I take your point that the intention may be that the two examples given may be the only ones which are true in all cases. I will have to look into this further. BTW exactly the same thing happens when you study law, or the letters of St Paul too closely. There has recently been a debate about the significance of the word "and" (kai in the original greek) in one place in Ephesians 4 on uk.religion.christian. I think we are possibly demonstrating the limitations of natural language when applied to something as precise as programming. -- I am Robert Billing, Christian, inventor, traveller, cook and animal lover, I live near 0:46W 51:22N. http://www.tnglwood.demon.co.uk/ "Bother," said Pooh, "Eeyore, ready two photon torpedoes and lock phasers on the Heffalump, Piglet, meet me in transporter room three" ###### Newsgroups: alt.folklore.computers From: source@netcom.com (David Harmon) Subject: Re: C implementation where (void *) and (char *) not the same Content-Type: text/plain; charset=us-ascii Message-ID: <34d9844f.379864363@source.netcom.com> Sender: source@netcom12.netcom.com Content-Transfer-Encoding: 7bit Organization: Netcom On-Line Services X-Newsreader: Forte Agent 1.5/32.451 References: <3503a8bd.192554150@source.netcom.com> <69ohlb$pjm$1@darla.visi.com> Mime-Version: 1.0 Date: Sat, 17 Jan 1998 10:17:30 GMT Lines: 9 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!ix.netcom.com!source On 16 Jan 1998 20:58:19 GMT, seebs@plethora.net (Peter Seebach) wrote: >There are probably several where, say, (char *), (int *), and (double *) >are different. Yes, it turns out that the real issue is (void *) versus pointer to int or other arbitrary type. Thanks to everyone who responded; I now have the info I wanted. ###### From: "Michael Will" Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 17 Jan 1998 18:16:59 GMT Organization: AT&T WorldNet Services Lines: 11 Message-ID: <69qsir$t2s@mtinsc04.worldnet.att.net> References: <3503a8bd.192554150@source.netcom.com> <69ohlb$pjm$1@darla.visi.com> NNTP-Posting-Host: 12.70.47.96 X-Newsreader: Microsoft Internet News 4.70.1155 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-peer.sprintlink.net!news.sprintlink.net!Sprint!worldnet.att.net!newsadm Peter Seebach wrote: > No. The C standard requires that (char *) and (void *) have the same > representation. OK, I'm puzzled now. I understand the requirement that (void *) be capable of holding and casting back any type of pointer without loss. If it is also mandated to have the same representation as (char *) then why have a seperate type? Semantic reasons only? - Michael ###### From: seebs@plethora.net (Peter Seebach) Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 17 Jan 1998 19:01:14 GMT Organization: Plethora Internet Lines: 20 Message-ID: <69qv5q$9m6$1@darla.visi.com> References: <3503a8bd.192554150@source.netcom.com> <69ohlb$pjm$1@darla.visi.com> <69qsir$t2s@mtinsc04.worldnet.att.net> NNTP-Posting-Host: herd.plethora.net NNTP-Posting-Date: 17 Jan 1998 13:01:14 CST X-Newsreader: trn 4.0-test60 (5 October 1997) Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!news-xfer.siscom.net!streamer1.cleveland.iagnet.net!qual.net!news1.chicago.iagnet.net!iagnet.net!chippy.visi.com!visi.com!news-out.visi.com!not-for-mail In article <69qsir$t2s@mtinsc04.worldnet.att.net>, Michael Will wrote: >OK, I'm puzzled now. I understand the requirement that (void *) be >capable of holding and casting back any type of pointer without loss. >If it is also mandated to have the same representation as (char *) >then why have a seperate type? Semantic reasons only? Baggage. (char *) had to be able to hold anything in pre-ANSI C. (void *) was introduced to have the same features, without the dual-functionality, but enough old code uses (char *) that way that this had to be supported. -s -- seebs@plethora.net -- I am not speaking for my employer. Copyright '97 All rights reserved. Boycott Spamazon! End Spam. C and Unix wizard - send mail for help, or send money for a consultation. Visit my new ISP --- More Net, Less Spam! Plethora . Net ###### Path: ccw.ch!usenet From: Neil.Franklin.remove.this@ccw.ch Newsgroups: alt.folklore.computers Subject: Re: C implementation where (void *) and (char *) not the same Date: 19 Jan 1998 19:05:49 +0100 Organization: My own Private Self Lines: 24 Message-ID: <4t30tk3m.fsf@chonsp.franklin.lugs.ch> References: <3503a8bd.192554150@source.netcom.com> <69ohlb$pjm$1@darla.visi.com> <69qsir$t2s@mtinsc04.worldnet.att.net> X-Newsreader: Gnus v5.3/Emacs 19.34 Peter Seebach wrote: > No. The C standard requires that (char *) and (void *) have the same > representation. "Michael Will" got confused by that: >OK, I'm puzzled now. I understand the requirement that (void *) be >capable of holding and casting back any type of pointer without loss. >If it is also mandated to have the same representation as (char *) >then why have a seperate type? Semantic reasons only? IIRC, (void *) was introduced because of malloc() needing a return type. Momory malloc()ed needs to be usable for any data type. On processors where memory access larger than a byte can not be on any address (e.g. Xerox Alto, AMD 29000, Novix NC4000, DEC Alpha (?), ...) the pointer from malloc() has to fit the most pessimal case, i.e. (int *). On processors with variable lentgh pointers (e.g. Inmos T414/800) it must be the compatible with the shortest, i.e. also (int *). -- Neil.Franklin.remove.this@ccw.ch, http://www.ccw.ch/Neil.Franklin/ for Geek Code, Papernet, Voicenet, PGP public key see http: Mac, 95 and NT users are CLUEless (Command Line User Environment) If I go missing, its once again my newsfeed that has craped