Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Dummy Funtcions

Posted on 2004-04-04
Medium Priority
Last Modified: 2010-04-15
Please explain to me what is a dummy function, what is it useful for and what the difference between the other methods (if there are, what are they?)
Question by:thekng
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 10753845
Not sure what you mean about a "dummy function".
A macro is a pure text substitution done by the preprocessor, but kind looks like a function.

Can you rephrase are give more of the context where you heard of a dummy function?
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 200 total points
ID: 10754388
Hi thekng,

A dummy function is usually just an empty function.  At first glance it might seem silly to call such a function, but it can actually make sense in some circumstances.

Function tables are one place where you're likely to see dummy functions.  The following table could be used to process characters based on the characters value.  

int (*ExecuteFunction[256])(void) = {NULL, NULL, NULL, ...,  IsA, IsB, IsC, ...};

  if (ExecuteFunction[Character])
    ExecuteFunction[Character] (ParameterList);

int (*ExecuteFunction[256])(void) = {Ignore, Ignore, Ignore, ...,  IsA, IsB, IsC, ...};

  ExecuteFunction[Character] (ParameterList);

In the first example, ExecuteFunction[Character] must be explicitly checked to make sure that there is a function to execute.  The second example inserts a dummy function (Ignore) into the table.

Hope this helps,
LVL 12

Assisted Solution

stefan73 earned 100 total points
ID: 10755504
Hi thekng,
Besides the function table use that Kent already mentioned, dummy functions are often used in callback scenarios, such as GUI events. Unlike in Kent's example, in such an environment the API user doesn't have a choice of different implementations, since the calling code is not his (it's the OS/GUI/class lib, etc).

Imagine a situation like this:

struct AllPossibleThingsAUserCanDo{
    event_ptr key_pressed;
    event_ptr left_mouse_click;
    event_ptr right_mouse_click;
    event_ptr window_resized;

Now you want to ignore events -> you need a dummy handler.

Dummy methods (as opposed to functions) are often used in C++ class hierarchies to have a pre-defined interface where some parts of the classes implement some methods as ... dummies.

LVL 16

Accepted Solution

PaulCaswell earned 400 total points
ID: 10755659
As Kent suggests, the most common use of dummies is in tables of functions. Stephan's callbacks are also common uses, but this is more usually a function pointer rather than a function itself. E.G.:

// Callback before each expansion.
char * (*Expanding) (char * before,char * after) = NULL;


if ( Expanding != NULL ) (*Expanding) ( before, after );

A third use is for what I call link-time coding:

void Expanding ( char * before, char * after ) {};


Expanding ( before, after );


You can then put this code in a library and, with careful use of link parameters, you can write your own 'Expanding' without modifying the library code.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question