473,466 Members | 1,385 Online
Bytes | Software Development & Data Engineering Community
Create 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 3238
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
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
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
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
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
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
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
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
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
5
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.