Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #423

Re: Help needed with function pointer examples

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!nerds-end
From Uli Kusterer <ulimakesacompiler@googlemail.com>
Newsgroups comp.compilers
Subject Re: Help needed with function pointer examples
Date Sun, 15 Jan 2012 03:41:29 +0100
Organization Compilers Central
Lines 41
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <12-01-024@comp.compilers> (permalink)
References <12-01-006@comp.compilers>
NNTP-Posting-Host news.iecc.com
X-Trace leila.iecc.com 1326601947 89710 64.57.183.58 (15 Jan 2012 04:32:27 GMT)
X-Complaints-To abuse@iecc.com
NNTP-Posting-Date Sun, 15 Jan 2012 04:32:27 +0000 (UTC)
Keywords analysis
Posted-Date 14 Jan 2012 23:32:27 EST
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Xref x330-a1.tempe.blueboxinc.net comp.compilers:423

Show key headers only | View raw


On 06.01.2012, at 07:43, Swati wrote:
> We are doing an analysis on the usage of function pointers.
> We have considered one such example as GCC which uses function pointers.
> Can you suggest any other application which uses function pointers
> extensively.


 That is a vague, underspecified question if I ever heard one. What
exactly are you looking for with function pointers? Have you
implemented them in your compiler and want some examples to see if
your compiler implements everything necessary?

 Anyway, the first example that comes to mind is any application that
can dynamically trigger actions, or that has to translate files or
data into actions. E.g. many interpreters and emulators essentially
look like this (untested C code fragment, never compiled):

struct Instruction { int instructionIndex; int param1; int param2 };
typedef void (*InstructionFuncPtr)( Instruction inInstruction );

InstructionFuncPtr	gInstructions[2] = { AddInstruction, SubtractInstruction
};

void main(void)
{
	Instruction vInstructions[10];

	// ... read instructions from stdin or a file into 'vInstructions' ...

	for( int x = 0; vInstructions[x] != -1; x++ )
		gInstructions[ vInstructions[x].instructionIndex ]( vInstructions[x] );

	return 0;
}

Where AddInstruction and SubtractInstruction are two functions that actually
implement the given operations.

Cheers,
-- Uli Kusterer
http://stacksmith.com

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Help needed with function pointer examples Swati <swatirathi@cse.iitb.ac.in> - 2012-01-06 12:13 +0530
  Re: Help needed with function pointer examples Uli Kusterer <ulimakesacompiler@googlemail.com> - 2012-01-15 03:41 +0100
    Re: Help needed with function pointer examples arnold@skeeve.com (Aharon Robbins) - 2012-01-16 19:28 +0000
  Re: Help needed with function pointer examples glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-01-15 11:27 +0000
    Re: Help needed with function pointer examples torbenm@diku.dk (Torben Ægidius Mogensen) - 2012-01-16 17:33 +0100
      Re: Help needed with function pointer examples Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2012-01-17 16:28 +0100
  Re: Help needed with function pointer examples Tony Finch <dot@dotat.at> - 2012-01-19 14:07 +0000

csiph-web