From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,da46977c58c329df X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-08 04:24:29 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!ihug.co.nz!out.nntp.be!propagator-SanJose!in.nntp.be!dax.net!juliett.dax.net!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Ada's Slide To Oblivion ... References: <4519e058.0201310714.650888e1@posting.google.com> <3C598CAA.7040801@home.com> <3C59FCD3.928144FB@adaworks.com> <7v8za79id0.fsf@vlinux.voxelvision.no> <3C6288CB.3227AF20@cfmu.eurocontrol.be> <3C62D397.8040001@mail.com> <%rC88.3860$oC3.2148048@typhoon.san.rr.com> <3C63AB8A.F52337D8@cfmu.eurocontrol.be> From: Ole-Hjalmar Kristensen Message-ID: <7vlme4w4ax.fsf@vlinux.voxelvision.no> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 08 Feb 2002 12:23:48 GMT NNTP-Posting-Host: 193.216.12.150 X-Complaints-To: abuse@tele2.no X-Trace: juliett.dax.net 1013171028 193.216.12.150 (Fri, 08 Feb 2002 13:23:48 MET) NNTP-Posting-Date: Fri, 08 Feb 2002 13:23:48 MET Organization: Tele2 Norway AS Public Access Xref: archiver1.google.com comp.lang.ada:19766 Date: 2002-02-08T12:23:48+00:00 List-Id: Ian Wild writes: > David Brown wrote: > > > > Hyman Rosen wrote: > > > Ray Blaak wrote: > > >> You most certainly can: > > >> typedef void (*FUNC)(); > > >> int i = 0; > > >> FUNC f = (FUNC) &i; > > >> > > >> That this crashes with access violations on a sane OS is a good thing, but > > >> nothing in the language is preventing the code/data conversions. > > > > > > False. The typecast '(FUNC)&i' is not legal standard C or C++. > > > It's not even a case of undefined results - it's just illegal. > > > Some compilers permit it as an extension, though. > > > > Legality aside, I have yet to find a compiler that doesn't accept this. > > I'll agree that most compilers will accept it, but it's not > C and quite often doesn't do what you're expecting. > > > In fact, I have code that does this very thing, it creates a small > > amount of data that happens to be instructions, casts it to a function > > pointer and calls it. > > On, say, a high end PDP-11, or a 68000, or an 8086 (but not its > progeny!), code space and data space are physically separate. There > are wires that come out of the processor to say which space to use. On > such a system there's NO WAY to write to code space, and it's not > impossible that ??? This is pure fantasy. How do you think the code got into the code space in the first place? > > static int x [500]; > int main () { > if ((void*)&main == (void*)&x) > printf ("Yes\n"); > return 0; > } > > will print "Yes". You can fill your array x with > all manner of carefully chosen data, but any attempt > to call it will jump to the corresponding address > in /code space/, which here will re-start the program.