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-07 13:36:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.mathworks.com!portc01.blue.aol.com!news-east.rr.com!cyclone.kc.rr.com!news.kc.rr.com!cyclone3.kc.rr.com!news3.kc.rr.com!typhoon.san.rr.com!not-for-mail Sender: David Brown From: David Brown Subject: Re: Ada's Slide To Oblivion ... Newsgroups: comp.lang.ada 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> User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (Linux/2.4.16 (i686)) Message-ID: <%rC88.3860$oC3.2148048@typhoon.san.rr.com> Date: Thu, 07 Feb 2002 21:36:59 GMT NNTP-Posting-Host: 24.165.4.233 X-Complaints-To: abuse@rr.com X-Trace: typhoon.san.rr.com 1013117819 24.165.4.233 (Thu, 07 Feb 2002 13:36:59 PST) NNTP-Posting-Date: Thu, 07 Feb 2002 13:36:59 PST Organization: Road Runner Xref: archiver1.google.com comp.lang.ada:19731 Date: 2002-02-07T21:36:59+00:00 List-Id: 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. 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. There are a certain set of problems that would require hand-crafted assembly to implement if this were not allowed. These constructs are usually (hopefully) only done in OS implementations, and runtime libraries for languages. Dave Brown