473,505 Members | 14,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pointer Indirection Syntax

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;

/* usage */
if (*((PtrFuncPtr) LOCATION) != NULL)
{
(**LOCATION)(); /* Execute function */
}

The above "if" statement should be translated to:
If the value at 0x10000 is not NULL,
execute the function pointed to by the
value in location 0x10000.
The function takes void parameters and returns void.

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?}

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #1
3 3244
Thomas Matthews <Th****************************@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; /* usage */
if (*((PtrFuncPtr) LOCATION) != NULL)
{
(**LOCATION)(); /* Execute function */
} The above "if" statement should be translated to:
If the value at 0x10000 is not NULL,
execute the function pointed to by the
value in location 0x10000.
The function takes void parameters and returns void. 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.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates
Nov 14 '05 #2
Thomas Matthews <Th****************************@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; /* usage */
if (*((PtrFuncPtr) LOCATION) != NULL)
{
(**LOCATION)(); /* Execute function */
} The above "if" statement should be translated to:
If the value at 0x10000 is not NULL,
execute the function pointed to by the
value in location 0x10000.
The function takes void parameters and returns void. 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.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates
Nov 14 '05 #3
On 7 Apr 2004 19:00:51 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote:
Thomas Matthews <Th****************************@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
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
10435
by: Nobody | last post by:
excuse the "windows" code below, but this is a C++ question... or maybe a C. Anyways, I want a function where I can pass in an array of strings (variable count, variable size), so I defined this:...
110
9812
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
2
552
by: Thomas Matthews | last post by:
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...
10
2646
by: Adam Warner | last post by:
Hi all, Just before Christmas Chris Torek gave me some great advice about closures in C: <http://groups.google.co.nz/groups?selm=cqcl3k030vj%40news3.newsguy.com&output=gplain> It includes this...
204
12891
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
2
1881
by: bor_kev | last post by:
Hi, First of all, i want to use the new managed class syntax and STL.NET under Microsoft Visual (C++) Studio 2005 Beta. I read in a Microsoft...
3
2132
by: David Mathog | last post by:
This one is driving me slightly batty. The code in question is buried deep in somebody else's massive package but it boils down to this, two pointers are declared, the first is: char **resname...
12
5367
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
5
3618
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.