Re: Pointer Indirection Syntax

From: Eric Amick (eric-amick_at_comcast.net)
Date: 04/08/04


Date: Wed, 07 Apr 2004 19:04:30 -0400

On 7 Apr 2004 19:00:51 GMT, Joona I Palaste <palaste@cc.helsinki.fi>
wrote:

>Thomas Matthews <Thomas_MatthewsSpitsOnSpamBots@sbcglobal.net> scribbled the following:
>> Hi,
>
>> At my work, we have a need for a pointer to a pointer
>> to a function returning void and having void parameters.
>
>> Since this is an embedded system, we have to assign the
>> variable with a constant value (address).
>
>> We came up with the following:
>> #define LOCATION 0x10000
>> typedef void (*FuncPtr)(void);
>> typedef *FuncPtr PtrFuncPtr;
>> What is the syntax for declaring a pointer to a pointer
>> to a function taking no parameters and returning void?
>> {In other words, what is the syntax to combine the
>> two typedefs into one?}
>> {Or /where does the 2nd asterisk (*) get placed?}
>
>Let me try this by hand. I might screw up, so any C gurus out there,
>feel free to correct me.
>Function taking no parameters and returning void:
>void function(void)
>Pointer to a function taking no parameters and returning void:
>void (*function)(void)
>Pointer to a pointer to a function taking no parameters and returning
>void:
>void (**function)(void)
>I believe that's it.

That's fine, and the original typedefs were *almost* correct. Note the
change in the second:

typedef void (*FuncPtr)(void);
typedef FuncPtr *PtrFuncPtr;

In general, to create a typedef, declare a variable of the appropriate
type, then stick "typedef" in front.

-- 
Eric Amick
Columbia, MD


Relevant Pages

  • Re: confusion: casting function pointers
    ... pointer from the 'actual/other modules' that takes arguments of type ... list to types of void *). ... int main{ ... without a prototype, a number of special "promotion" rules take ...
    (comp.lang.c)
  • Re: [RFC] timers, pointers to functions and type safety
    ... * they have callback of type void ... callback is called by the code that even in theory has no ... cast to unsigned long and cast back in the callback. ... number - not a pointer cast to unsigned long, not an index in array, etc. ...
    (Linux-Kernel)
  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... You can't do pointer arithmetic on a void* value. ... qsort behaves in a manner consistent with its specification. ... actually works as advertised...but doesn't mean that the cast is ...
    (comp.lang.c)
  • Re: void pointers
    ... A void pointer is an address of a region of memory (which may or may not ... This creates an array of 5 pointers to void. ... This is casting an int to a void *. ...
    (comp.lang.c)
  • Re: The void** pointer breaking symmetry?
    ... void** is a generic pointer type that can be implicitly converted ... because dereferencing the void ** variable once gives ...
    (comp.lang.c)