Re: [cc65] array of pointers to functions question

From: Mark J. Reed <markjreed1mail.com>
Date: 2010-05-15 16:03:24
On Sat, May 15, 2010 at 3:26 AM, Chiron Bramberger
<chiron@bramberger.com> wrote:
> ...in short, why does this work:
> -----
> void (*vibrato_change)() = vib_chg;
> void (*lfo_change)() = lfo_chg ;
>
> void (*command[])() = {vib_chg,lfo_chg }; // gives me an array of pointers
> to functions
>
> -----
> and this doesn't:
> -----
> void (*vibrato_change)();
> void (*lfo_change)();
> vibrato_change = vib_chg;
> lfo_change = lfo_chg ;
>
> void (*command[])() = {vib_chg,lfo_chg };
>
> //Error: Expression expected

You can't mix declarations and statements.  An initialization is part
of a declaration:

int foo = 1; // declaration
int bar; // OK

But a separate assignment statement is runtime executable code, which
terminates the declarations phase.

int foo;  // declaration
foo = 1;  // assignment
int bar;  // ILLEGAL

> ----------
>
> THANKS!!!!!!
> -Chiron
>
>
>
> ----- sample code below -----
>
>
>
> #include <stdio.h>
> #include <stdlib.h>
>
>
>
>
>
> void vib_chg() {
>
>     printf("vib -> do me!\n");
>
> }//end func
>
>
> void lfo_chg() {
>
>     printf("lfo - > do me!\n");
>
> }//end func
>
>
>
>   int main(){
>
>         // works! creates pointers to functions,
>         // then creates array of those pointers to functions
>
>       //void (*vibrato_change)() = vib_chg;
>       //void (*lfo_change)() = lfo_chg ;
>
>       //void (*command[])() = {vib_chg,lfo_chg };
>
>       //command[0]();
>       //command[1]();
>
>       //return EXIT_SUCCESS;
>
> //}//end main
>
>     // the following returns errors: (see end of file)
>     // why doesn't this version work?
>     // does it have something to do with declaring functions
>     // and then variables, and then functions again?
>
>     void (*vibrato_change)();
>     void (*lfo_change)();
>
>     vibrato_change = vib_chg;
>     lfo_change = lfo_chg ;
>
>     void (*command[])() = {vib_chg,lfo_chg };
>
>     command[0]();
>     command[1]();
>
>
>
>     return EXIT_SUCCESS;
>
>   }//end main
>
>
>
> /**********
>
> results for working program (the one commented out above)
> as run on a commodore pet
>
> *** commodore basic 4.0 ***
>
>  31743 bytes free
>
> ready.
> load"array?of?funcs.prg",8,1:
>
> searching for array?of?funcs.prg
> loading
> ready.
> run
> vib -> do me!
> lfo - > do me!
>
> ready.
>
>
> **********
>
> results for non-working programm
>
> compile error output:
>
> C:\6502\cc65\bin>cl65 -t pet array_of_funcs_ALT.c -o array_of_funcs_ALT.prg
> array_of_funcs_ALT.c(52): Error: Expression expected
> array_of_funcs_ALT.c(52): Warning: Statement has no effect
> array_of_funcs_ALT.c(52): Error: `;' expected
> array_of_funcs_ALT.c(52): Error: Expression expected
> array_of_funcs_ALT.c(52): Warning: Statement has no effect
> array_of_funcs_ALT.c(52): Error: `;' expected
> array_of_funcs_ALT.c(52): Error: Expression expected
> array_of_funcs_ALT.c(52): Warning: Statement has no effect
> array_of_funcs_ALT.c(52): Error: `;' expected
> array_of_funcs_ALT.c(52): Error: Expression expected
> array_of_funcs_ALT.c(52): Warning: Statement has no effect
> array_of_funcs_ALT.c(52): Error: `;' expected
> array_of_funcs_ALT.c(52): Error: Expression expected
> array_of_funcs_ALT.c(52): Warning: Statement has no effect
> array_of_funcs_ALT.c(52): Error: `;' expected
> array_of_funcs_ALT.c(52): Error: Expression expected
> array_of_funcs_ALT.c(52): Fatal: Too many errors
>
> **********/
>
>
>
>
>



-- 
Mark J. Reed <markjreed@gmail.com>
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat May 15 16:03:30 2010

This archive was generated by hypermail 2.1.8 : 2010-05-15 16:03:34 CEST