Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) Newsgroups: comp.lang.c Subject: Re: Variable function names Message-ID: <193@fxgrp.UUCP> Date: 5 Jan 88 19:15:50 GMT References: <973@russell.STANFORD.EDU> <47000025@uxe.cso.uiuc.edu> <2006@cognos.UUCP> Reply-To: fxgrp!ljz@ames.arpa (Lloyd Zusman, Master Byte Software) Followup-To: <2006@cognos.UUCP> jimp@cognos.UUCP (Jim Patterson) Organization: FX Development Group, Inc., Mountain View, CA Lines: 40 In article <47000025@uxe.cso.uiuc.edu> mcdonald@uxe.cso.uiuc.edu writes: > ... >I learned C with the explicit assumption that, since it allowed both >data and function pointers, one could take an array, write a program that >generated compiled code in that array, cast the address of (the first >byte of) the array to a function pointer, and call that function. > I have since learned that on some systems (i.e. 80286 Xenix in anything >except single-segment model) it won't work, and that ANSI C does not >require it to work (A FATAL FLAW). > ... I agree with some of the others here that this is anything but "A FATAL FLAW". It's hardly a flaw that a language that was designed as a compiled language would not always work properly when some machine- dependent side effects of the language that sometimes allow it to be used in an interpretive manner don't work on all architectures and hence are not required as features of the language. Back in the days of FORTRAN, I wrote some code that would go through memory and find the FORMAT statement strings, and that would alter them at run-time. This gave me execution-time-modifiable FORMAT statements which, although useful, are not a feature of the language. This code I wrote only worked for a particular FORTRAN implementation on a particular operating system on a particular machine. Putting machine code into a block of memory at run-time and executing it is a slick feature, but it's foolish to expect such a thing to be portable ... or to even be possible at all on some architectures, as some people here have already pointed out. Making this a feature of a language one of whose prime features is portability would be silly, in my opinion. Sure, if your operating system and machine architecture allow this to be done, and if you don't care whether your code is portable, then by all means do it if you must. But don't expect someone to design C to make it easy on you. ------------------------------------------------------------------------- Lloyd Zusman Master Byte Software Los Gatos, California Internet: fxgrp!ljz@ames.arpa "We take things well in hand." UUCP: ...!ames!fxgrp!ljz