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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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 02:36:52 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news2.kpn.net!news.kpn.net!nslave.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader1.kpnqwest.net.POSTED!not-for-mail Message-ID: <3C63AB8A.F52337D8@cfmu.eurocontrol.be> From: Ian Wild Reply-To: ian.wild@eurocontrol.int Organization: Eurocontrol X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.0.30 i686) X-Accept-Language: en MIME-Version: 1.0 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cache-Post-Path: ecw.eurocontrol.be!unknown@193.221.189.77 X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) Date: Fri, 08 Feb 2002 10:36:51 GMT NNTP-Posting-Host: 193.221.170.178 X-Complaints-To: abuse@Belgium.EU.net X-Trace: nreader1.kpnqwest.net 1013164611 193.221.170.178 (Fri, 08 Feb 2002 11:36:51 MET) NNTP-Posting-Date: Fri, 08 Feb 2002 11:36:51 MET Xref: archiver1.google.com comp.lang.ada:19760 Date: 2002-02-08T10:36:51+00:00 List-Id: 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 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.