avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Pointer to a function in a structure in flash?


From: E . Weddington
Subject: Re: [avr-gcc-list] Pointer to a function in a structure in flash?
Date: Mon, 27 Oct 2003 22:20:30 GMT

<snip> 

> #define STRCMP(x,y) strcmp_P( x, (PGM_P) pgm_read_word( 
&y ) )/* for GCC
> */
> 
> Below 'token' is from strtok() RAM buffer with what you 
typed like "Baud 
> 1200".
> 
>      for( i = 0; i < COMMANDS_AVAILABLE; ++i )
>       {/* If find a table match then call that function 
*/
>           if( !STRCMP( (const char *) token , 
cmd_func_table[i].command ) )
>               {
> ....
>               /* Call the function from the function 
table */
>               #if defined( __IAR__ )
>                   retval = ( *(cmd_func_table
[i].function) )( (char const *)
token,>  
> (char const *) tokptr );
>               #endif
>               #if defined( __GCC_VERSION__ )
>                   retval = 
> (*((functype_t)(pgm_read_word(&cmd_func_table
[i].function))))((char
const>  
> *)token,              (char const *)tokptr);
>               #endif
> ....
>              }
>        }
> 
> Keep in mind this is code that is working fine with IAR.
> 

[Sorry for any weird wrapping above.]

You also wrote:

"If a command in my table takes no parameters, 
say "Status?" it does what it should, but commands that do 
take parameters, for example "Baud 1200", are not found 
when the table is searched."

Then this sounds like it's an issue with getting 'token' 
from strtok, not the execution of the function after 
identifying the command.

Can you do some simple tests to make sure that 'token' has 
the same string (your command) in IAR and in GCC, with 
commands that have parameters?

Also, shouldn't you change the GCC portion (above) to:

#if defined( __GCC_VERSION__ )
retval = cmd_func_table[0].function((CONST char *) token, 
(CONST char *) tokptr);
#endif

HTH
Eric





reply via email to

[Prev in Thread] Current Thread [Next in Thread]