473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

complex pointer declaration

Guys,

I am sorry for asking so many questions.

I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.

I could declare an array of pointers to functions, but not the
complete thing.

I declared the,
array of pointers to functions (where each functions takes void as
argument and returns int) as follows:
int (*ptr [] ) (void); // Hope this is correct

Please help me to declare a pointer to above type.

Again many thanks for any help.....

Sep 19 '07 #1
9 3498
ju**********@yahoo.co.in said:
Guys,

I am sorry for asking so many questions.

I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.
typedef is your friend. Start off by setting up a synonym for the function
type:

typedef int junkyfunc(void);

Now let's have an array of pointers:

#define N 32 /* or whatever */

typedef junkyfunc *array_of_N_jf_ptrs[N];

Now we can easily define a pointer to such an array:

array_of_N_jf_ptrs *p;

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 19 '07 #2
Richard Heathfield wrote:
ju**********@yahoo.co.in said:
>Guys,

I am sorry for asking so many questions.

I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.

typedef is your friend. Start off by setting up a synonym for the function
type:

typedef int junkyfunc(void);

Now let's have an array of pointers:

#define N 32 /* or whatever */

typedef junkyfunc *array_of_N_jf_ptrs[N];

Now we can easily define a pointer to such an array:

array_of_N_jf_ptrs *p;
Hmmm. Is it actually necessary, in most cases, to distinguish between a
a pointer to an array of such functions and a pointer to the first
function in such an array?

Sep 19 '07 #3
On Sep 19, 6:29 pm, Richard Heathfield <r...@see.sig.invalidwrote:
junky_fel...@yahoo.co.in said:
Guys,
I am sorry for asking so many questions.
I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.

typedef is your friend. Start off by setting up a synonym for the function
type:

typedef int junkyfunc(void);

Now let's have an array of pointers:

#define N 32 /* or whatever */

typedef junkyfunc *array_of_N_jf_ptrs[N];

Now we can easily define a pointer to such an array:

array_of_N_jf_ptrs *p;
Thanks Richard. This is really a nice way of declaring complex types.

Sep 19 '07 #4
On Sep 19, 6:45 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
Richard Heathfield wrote:
junky_fel...@yahoo.co.in said:
Guys,
I am sorry for asking so many questions.
I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.
typedef is your friend. Start off by setting up a synonym for the function
type:
typedef int junkyfunc(void);
Now let's have an array of pointers:
#define N 32 /* or whatever */
typedef junkyfunc *array_of_N_jf_ptrs[N];
Now we can easily define a pointer to such an array:
array_of_N_jf_ptrs *p;

Hmmm. Is it actually necessary, in most cases, to distinguish between a
a pointer to an array of such functions and a pointer to the first
function in such an array?- Hide quoted text -
Actually, I need to find the number of elements in the array. So, I
must know its type. By having a pointer to first element, I cannot do
that.

Sep 19 '07 #5
Mark Bluemel <ma**********@pobox.comwrites:
Richard Heathfield wrote:
>ju**********@yahoo.co.in said:
>> I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.
typedef is your friend. Start off by setting up a synonym for the
function type:
typedef int junkyfunc(void);
Now let's have an array of pointers:
#define N 32 /* or whatever */
typedef junkyfunc *array_of_N_jf_ptrs[N];
Now we can easily define a pointer to such an array:
array_of_N_jf_ptrs *p;

Hmmm. Is it actually necessary, in most cases, to distinguish between
a a pointer to an array of such functions and a pointer to the first
function in such an array?
Yes, it's necessary to distinguish between a pointer to an array and a
pointer to the first element of an array. The main difference is that
pointers to arrays are rarely useful.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 19 '07 #6
"ju**********@yahoo.co.in" <ju**********@yahoo.co.inwrites:
On Sep 19, 6:45 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
[...]
>Hmmm. Is it actually necessary, in most cases, to distinguish between a
a pointer to an array of such functions and a pointer to the first
function in such an array?

Actually, I need to find the number of elements in the array. So, I
must know its type. By having a pointer to first element, I cannot do
that.
If you declare a pointer to an array, the size of the array must be
fixed at compilation time (unless you're using VLAs, which aren't
universally supported).

Pointers to arrays are rarely as useful as pointers to the first
element of an array. You can use ordinary indexing to access all the
elements of the array. You just have to keep track of the size
separately.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 19 '07 #7
"ju**********@yahoo.co.in" wrote:
Mark Bluemel <mark_blue...@pobox.comwrote:
>Richard Heathfield wrote:
>>junky_fel...@yahoo.co.in said:
>>>I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.
>>typedef is your friend. Start off by setting up a synonym for
the function type:
>> typedef int junkyfunc(void);
>>Now let's have an array of pointers:
>> #define N 32 /* or whatever */
typedef junkyfunc *array_of_N_jf_ptrs[N];
>>Now we can easily define a pointer to such an array:
>> array_of_N_jf_ptrs *p;

Hmmm. Is it actually necessary, in most cases, to distinguish
between a a pointer to an array of such functions and a pointer
to the first function in such an array?

Actually, I need to find the number of elements in the array. So,
I must know its type. By having a pointer to first element, I
cannot do that.
Sure you can. When you allocate memory to p with:
p = malloc(N * sizeof *p;
just remember the value of N. If you define a local variable for
the array, with:
arr_of_N_jf_ptrs arr[N];
you can either retain N or recover the value (in the same scope)
with "(sizeof arr)/sizeof arr[0])".

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Sep 20 '07 #8
Keith Thompson wrote:
Mark Bluemel <ma**********@pobox.comwrites:
>Hmmm. Is it actually necessary, in most cases, to distinguish between
a a pointer to an array of such functions and a pointer to the first
function in such an array?

Yes, it's necessary to distinguish between a pointer to an array and a
pointer to the first element of an array. The main difference is that
pointers to arrays are rarely useful.
Yes. I think that was what I was trying to express - but failed...
Sep 20 '07 #9
On Wed, 19 Sep 2007 06:21:30 -0700, ju**********@yahoo.co.in wrote:
Guys,

I am sorry for asking so many questions.

I need to declare a pointer to an array of pointer to functions
where each function takes void as an argument and returns int.
f -- f
*f -- is a pointer
(*f)[N] -- to an N-element array
*(*f)[N] -- of pointer
(*(*f)[N])() -- to function
(*(*f)[N])(void) -- taking void
int (*(*f)[N])(void) -- and returning int

Hope that helps. Typedefs would make it more readable; naked pointers are
a bit ugly.
Sep 21 '07 #10

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

Similar topics

7
by: Michael Birkmose | last post by:
Hi everyone!, Are pointers to incomplete types allowed in ANSI C? I can see that pointer arithmic on pointers to incomple types is impossible, however there are situations where it can be...
3
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void...
7
by: Alan Holloway | last post by:
Hi all, Firstly thanks for your golden insight on my earlier post re bitwise operations. I now have another question! I've just been reading the excellent Peter van der Linden excerpt ...
9
by: Christopher Benson-Manica | last post by:
Recently, the following definition was posted to comp.lang.c++: > char **Arr; 1) Is the type of this object "array of 3 (array of two of pointer to pointer to char)"? If not, what is it? ...
0
by: masood.iqbal | last post by:
I have always had trouble correctly interpreting complex type declarations without using the "declarator parser" program given in K&R. Then someone taught me about the "Clockwise" Rule. Start with...
12
by: noor.fatma | last post by:
Hi, recently I attended a test on C where I was asked to declare the following declarations in one line. void ** ( *p )(int *, char *); int *a; how should i do this shall i use typedef...
3
by: Rav | last post by:
hi, i need a function, preferably a program for parsing the complex declarations in C. Can anyone help me in this regard...i appreciate. i work on Turbo C++ 3.0 in windows environment. Also, plz...
6
by: Cric | last post by:
Hi, how can be the declaration of a pointer which points to dynamic array of pointers and each pointer from this array points to an dynamic array of pointers which points to character strings...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.