I want to initialize an array of function pointers (global)
If I do it like:
/* definition of foo_1, foo_2, foo_3 all return void and take no args */
void (* foo[3]) ();
foo[0] = foo_1 ;
foo[1] = foo_2 ;
foo[2] = foo_3 ;
I get a compile time error, but if initialized like :
/* definition of foo_1, foo_2, foo_3 all return void and take no args */
void (* foo[3]) () = {foo_1 , foo_2, foo_3 };
There is no error, why? 4 9619
On 9 Dec 2003 23:15:09 -0800, an***********@y ahoo.co.in (Aniruddha) wrote: I want to initialize an array of function pointers (global) If I do it like:
/* definition of foo_1, foo_2, foo_3 all return void and take no args */ void (* foo[3]) (); foo[0] = foo_1 ; foo[1] = foo_2 ; foo[2] = foo_3 ;
I get a compile time error, but if initialized like :
/* definition of foo_1, foo_2, foo_3 all return void and take no args */ void (* foo[3]) () = {foo_1 , foo_2, foo_3 };
There is no error, why?
There shouldn't be an error.
Perhaps the error for the assignments is due to having those assignments
outside any function.
Without further information it's impossible to say -- post a minimal
complete program that demonstrates the problem. al***@start.no (Alf P. Steinbach) wrote in message news:<3f******* *********@News. CIS.DFN.DE>... On 9 Dec 2003 23:15:09 -0800, an***********@y ahoo.co.in (Aniruddha) wrote:
I want to initialize an array of function pointers (global) If I do it like:
/* definition of foo_1, foo_2, foo_3 all return void and take no args */ void (* foo[3]) (); foo[0] = foo_1 ; foo[1] = foo_2 ; foo[2] = foo_3 ;
I get a compile time error, but if initialized like :
/* definition of foo_1, foo_2, foo_3 all return void and take no args */ void (* foo[3]) () = {foo_1 , foo_2, foo_3 };
There is no error, why?
There shouldn't be an error.
Perhaps the error for the assignments is due to having those assignments outside any function.
The initialization is not in any function (global), but the second
version works not the first.
On 9 Dec 2003 23:15:09 -0800, an***********@y ahoo.co.in (Aniruddha) wrote: I want to initialize an array of function pointers (global) If I do it like:
/* definition of foo_1, foo_2, foo_3 all return void and take no args */ void (* foo[3]) (); foo[0] = foo_1 ; foo[1] = foo_2 ; foo[2] = foo_3 ;
What error do you get?
void foo_1( void )
{
return;
}
void foo_2( void )
{
return;
}
void foo_3( void )
{
return;
}
void (* foo[3]) ();
int main( void )
{
foo[0] = foo_1 ;
foo[1] = foo_2 ;
foo[2] = foo_3 ;
return 0;
}
Generates no errors. Are you putting
foo[0] = foo_1 ;
foo[1] = foo_2 ;
foo[2] = foo_3 ;
inside a function? You must.
--
#include <standard.discl aimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
On 10 Dec 2003 20:47:07 -0800, an***********@y ahoo.co.in (Aniruddha)
wrote: al***@start. no (Alf P. Steinbach) wrote in message news:<3f******* *********@News. CIS.DFN.DE>... On 9 Dec 2003 23:15:09 -0800, an***********@y ahoo.co.in (Aniruddha) wrote:
>I want to initialize an array of function pointers (global) >If I do it like: > >/* definition of foo_1, foo_2, foo_3 all return void and take no args */ >void (* foo[3]) (); > foo[0] = foo_1 ; > foo[1] = foo_2 ; > foo[2] = foo_3 ; > >I get a compile time error, but if initialized like : > >/* definition of foo_1, foo_2, foo_3 all return void and take no args */ >void (* foo[3]) () = {foo_1 , foo_2, foo_3 }; > >There is no error, why?
There shouldn't be an error.
Perhaps the error for the assignments is due to having those assignments outside any function.
The initialization is not in any function (global), but the second version works not the first.
In the second, the initialization is part of the definition.
In the first, the initialization is separate from the definition. The
definition is complete before any of the assignment statements are
processed. The initialization statements are not part of any
definition or declaration. But definitions and declarations are the
only things allowed outside of a function. Consequently, the
initialization statements are not placed properly and a diagnostic is
required.
<<Remove the del for email>> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Felix Kater |
last post by:
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
|
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 about the syntax
of calling the same.
#include <stdio.h>
void fp1()
|
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....
|
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...
|
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,...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |