On 10 Dec 2003 20:47:07 -0800,
(Aniruddha)
wrote:
> (Alf P. Steinbach) wrote in message news:<>...
>> On 9 Dec 2003 23:15:09 -0800, (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>>