Xref: utzoo comp.lang.c:12475 comp.std.c:366 Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!ames!haven!cvl!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Calling functions by address Message-ID: <13478@mimsy.UUCP> Date: 10 Sep 88 04:54:17 GMT References: <758@goofy.meest.UUCP <707@starfish.Convergent.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 47 In article <707@starfish.Convergent.COM> cdold@starfish.Convergent.COM (Clarence Dold) writes: >... For QuickC, running on a PC, jumps to a ROM based routine (actually the >reset jump for an 8088 CPU chip)... > >main () >{ > void (far *bye) (); > int far *pt; > > pt = ((int far *) (0x0000472L); [missing ) somewhere here] > *pt = 0x1234; /* for warm boot */ > /* *pt = 0x0000; */ /* for cold boot */ > > bye = (void far *) 0x0ffff0000L; > (*bye) (); >} Incidentally, this program can be `simplified' (and from dumb-but-fast compilers, the resulting code probably will be noticeably shorter) to main() { *(int far *)0x472L = 0x1234; /* warm boot */ /* = 0 cold boot */ (*(void (far *)())0xffff0000L)(); } The addresses can (and probably should) be prettied up with `#define's, at least for anything even slightly more substantial than this example. (I confess to being somewhat surprised at the difference between warm and cold boots; more often, a warm boot is done by jumping to some other address than the ROM restart address. Something like #define COLDBOOT ((void (*)())0xfc000000) #define WARMBOOT ((void (*)())0xfc000004) (*(cold ? COLDBOOT : WARMBOOT))(); or if you prefer the readable version :-) , if (cold) (*COLDBOOT)(); else (*WARMBOOT)(); ) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris