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

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

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


From: Bob Paddock
Subject: [avr-gcc-list] Pointer to a function in a structure in flash?
Date: Mon, 27 Oct 2003 11:04:11 -0500
User-agent: Opera7.21/Win32 M2 build 3218


I'm having more problems converting code from IAR to GCC, in getting info from
flash:

I have this structure:

typedef struct /* define the struct 'cmd_entry' */
{
    /* Pointer to string in flash: */
    PGM_P command;

/* Pointer to function in flash returning an int, passed a char pointer: */
    uint16_t  (*function)(CONST char * tok_buf, CONST char * tok_ptr);
}str_func_entry;

This IAR code does what I want:
    flash_str_out( cmd_func_table[i].command );

which to get to work in GCC I had to change to this:

    flash_str_out( (PGM_P) pgm_read_word( &cmd_func_table[i].command ) );

However I can not figure out the right magic words to convert this section, that has a
pointer to a function in a structure in flash:

Working IAR code snippet (STRCMP = strcmp_P):
 /* 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: */
retval = ( *(cmd_func_table[i].function) )( (char const *) token, (char const *) tokptr );
 }

I tried this, and other variations, with various casts:
retval = ( *(pgm_read_word( &cmd_func_table[i].function )) )( (char const *) token, (char const *) tokptr );

but then I get errors like "object is not function" or
 "invalid type argument of 'unary *'".

Suggestions?

This whole function pointer/structure thing came about to get IAR to work, which I need
to be compatible with.



reply via email to

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