flexible function parameter

From: Michael (mic457_at_gmx.net)
Date: 04/30/04


Date: Fri, 30 Apr 2004 15:19:25 +0200

Hi all,

I've got a question according the design
of a parameterlist in C. I am going to have
a function taking two parameters.

One is supposed to be used as a flag, which
determines the type of data is needed, which
is passed to the function by the second parameter.
The type of this parameters differs depending on
the flag. E.g.

void doSomething ( int flag, <seeBelow> value)
{
   ...
   switch flag
   {
    case 1: // I need value to be a double
            ...
    case 2: // Value shoud be an int
   ...
   }
   ...
}
Since the number of different types is finite,
I wonder what is the best bet to pass the 2nd Parameter
  a) Build a struct, containing all possibilities
     of which only the needed are set
  b) Use a void pointer
  c) Something else

Thanks
Michael



Relevant Pages

  • Re: MFC and Worker Thread issue
    ... read Doug H. essay on how it's best to use AfxBeginThread ... Sutter's series on concurrent programming in DDJ ain't bad, ... signal to thread that it should finish through a boolean flag. ... design so that you can use INFINITE. ...
    (microsoft.public.vc.mfc)
  • [RFC PATCH 12/15] ima-path-check rework
    ... if (flag & O_NOATIME) ... goto exit; ... struct dentry *dentry, int acc) ... struct fanotify_event_metadata *metadata, ...
    (Linux-Kernel)
  • Re: The Flag the Cross and ID
    ... of a large US Flag, backlit with sunshine, clearly showing an image of ... hardly a miracle unless you regard the wave nature of light to be a miracle ... It only looks like a traditional cross because the photographer moved to ... But those two competing "design ...
    (talk.origins)
  • Re: [PATCH 5/9] writeback: support > 1 flusher thread per bdi
    ... The writeback thread checks for race added work on exit, ... I believe we can bear one more "int" for flags in the struct bdi_work ... There would be no "on stack" flag. ... enum writeback_sync_modes sync_mode) ...
    (Linux-Kernel)
  • Re: The Flag the Cross and ID
    ... of a large US Flag, backlit with sunshine, clearly showing an image of ... one would expect IDers who promote Complex Specified Information ... independent of human design. ... The examples of CSI are not framed as alternatives to evolution, ...
    (talk.origins)