473,657 Members | 2,479 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.l earn.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 3255
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)(voi d)
Pointer to a pointer to a function taking no parameters and returning
void:
void (**function)(vo id)
I believe that's it.

--
/-- Joona Palaste (pa*****@cc.hel sinki.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)(voi d)
Pointer to a pointer to a function taking no parameters and returning
void:
void (**function)(vo id)
I believe that's it.

--
/-- Joona Palaste (pa*****@cc.hel sinki.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.hel sinki.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)(voi d)
Pointer to a pointer to a function taking no parameters and returning
void:
void (**function)(vo id)
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
10441
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: void Test(LPCTSTR* ppsz, int nCount) { for (int nIndex = 0; nIndex < nCount; nIndex++)
110
9899
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 must be an object instead of
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 constant value (address). We came up with the following: #define LOCATION 0x10000
10
2660
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 declaration of a function pointer variable called fp: void (*fp)(void *); What does the syntax above mean? I can only digest it as void * fp, i.e. fp is a pointer to void.
204
12984
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 = {0,1,2,4,9};
2
1886
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 article(http://msdn.microsoft.com/VISUALC/default.aspx?pull=/library/en-us/dnvs05/html/stl-netprimer.asp) that i am suposed to include : #include <cli/vector> #include <algorithm>
3
2147
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 which is part of the "atoms" structure that is passed into the function from the outside. I have not yet found where it is allocated but I'm reasonably sure from other chunks of this code that it was by:
12
5385
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
5
3640
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 10 member functions. Can switch be replaced to member function pointer array? Please provide me an example of source code to show smart pointer inside class. Thanks....
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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 we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.