473,404 Members | 2,137 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,404 software developers and data experts.

call function with function pointer array as argument

Hi,

I've got a function with an array of 12 function pointers as an argument. When calling it: Is there a way to directly insert and fill the array argument (using braces {} or whatever) -- or do I need to fill an array first and then pass it as an argument?

Felix
May 10 '06 #1
1 1913

Felix Kater wrote:
Hi,

I've got a function with an array of 12 function pointers as an argument. When calling it: Is there a way to directly insert and fill the array argument (using braces {} or whatever) -- or do I need to fill an array first and then pass it as an argument?


The following is not ISO-C (gcc generates the warning:
"a.c:20: warning: ISO C90 forbids compound literals"),
but it might be what you're looking for:

int foo0(void) {return 0;}
int foo1(void) {return 1;}
int foo2(void) {return 2;}
int foo3(void) {return 3;}

void FOO( int (**f)(void), int i)
{
for (; i>=0; i--)
printf("%d\n", f[i]());
}

typedef int (*f_array[4])(void);

int main(void)
{
f_array f;

FOO( (f_array){foo0, foo1, foo2, foo3}, 3);
}

May 10 '06 #2

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
27
by: Marlene Stebbins | last post by:
I am experimenting with function pointers. Unfortunately, my C book has nothing on function pointers as function parameters. I want to pass a pointer to ff() to f() with the result that f() prints...
8
by: andrew.fabbro | last post by:
In a different newsgroup, I was told that a function I'd written that looked like this: void myfunc (char * somestring_ptr) should instead be void myfunc (const char * somestring_ptr) ...
9
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
7
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h>...
2
by: Rufus | last post by:
Hi all, I have a problem with the next example code. I can't compile it without warnings with gcc. The compilation out is: $ gcc -Wall aPoint.c aPoint.c: In function 'printaPoint2':...
22
by: Nehil | last post by:
Does C follow call by value convention or call by reference? i see that there is nothing like reference in C standard but it is referenced. still, what should be the answer for the above...
21
by: mdh | last post by:
Hi Group, I know there have been many questions on this topic, but I wish to clarify this very basic concept. in: int main(){ int j; j = f(8); .....}
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.