Shop OBEX P1 Docs P2 Docs Learn Events
Function pointer array warnings — Parallax Forums

Function pointer array warnings

Mark MaraMark Mara Posts: 64
edited 2013-12-23 07:27 in Propeller 1
I am working on some code that uses a couple of function pointer arrays. I want to initialize these arrays at compile time. The following code works, but it generates a pile of warning messages.
#define _CHAR_TOKENS    9  
#define _CHAR_STATES    4


int main(void)
{
/* fsm fuctions */
int char_nop(char *,char **);                    // 0
int char_esc(char *,char **);                    // 1
int char_add_char(char *,char **);               // 2
int char_remove(char *,char **);                 // 3
int char_add_dlim(char *,char **);               // 4
int char_add_quote_char_process(char *,char **); // 5
int char_add_process(char *,char **);            // 6
int char_delim_add(char *,char **);              // 7
int char_eof_process(char *,char **);            // 8


/* character processor action table - initialized with fsm fuctions */
typedef void (*ACTION_PTR)(char *,char **); 
ACTION_PTR char_action[_CHAR_TOKENS][_CHAR_STATES] = {     
/* ESC   */ {char_esc,      char_esc,                    char_esc,         char_esc         },
/* SPACE */ {char_nop,      char_add_char,               char_add_char,    char_nop         },
/* COLON */ {char_nop,      char_add_char,               char_add_char,    char_nop         },
/* SLASH */ {char_nop,      char_add_char,               char_add_char,    char_nop         },
/* BSPACE*/ {char_nop,      char_remove,                 char_remove,      char_remove      },
/* QUOTE */ {char_add_char, char_add_dlim,               char_delim_add,   char_delim_add   },
/* CR    */ {char_nop,      char_add_quote_char_process, char_add_process, char_add_process },
/* other */ {char_add_char, char_add_char,               char_add_char,    char_add_char    }};


/* character processor state transition table */
int char_new_state[_CHAR_TOKENS][_CHAR_STATES] ={
/* ESC   */ {0, 0, 0, 0},
/* SPACE */ {0, 1, 3, 3},
/* COLON */ {0, 1, 3, 3},
/* SLASH */ {0, 1, 3, 3},
/* BSPACE*/ {0, 1, 2, 3},
/* QUOTE */ {1, 3, 1, 1},
/* CR    */ {0, 0, 0, 0},
/* other */ {2, 1, 2, 2}};


  return 0;
}
Project Directory: /Users/mam1/Documents/GCC Master/post/


propeller-elf-gcc -v GCC 4.6.1 (propellergcc_v1_0_0_2224)
propeller-elf-gcc -I . -L . -o cmm/post.elf -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 post.c
post.c: In function 'main':
post.c:24:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:24:13: warning: (near initialization for 'char_action[0][0]') [enabled by default]
post.c:24:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:24:13: warning: (near initialization for 'char_action[0][1]') [enabled by default]
post.c:24:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:24:13: warning: (near initialization for 'char_action[0][2]') [enabled by default]
post.c:24:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:24:13: warning: (near initialization for 'char_action[0][3]') [enabled by default]
post.c:25:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:25:13: warning: (near initialization for 'char_action[1][0]') [enabled by default]
post.c:25:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:25:13: warning: (near initialization for 'char_action[1][1]') [enabled by default]
post.c:25:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:25:13: warning: (near initialization for 'char_action[1][2]') [enabled by default]
post.c:25:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:25:13: warning: (near initialization for 'char_action[1][3]') [enabled by default]
post.c:26:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:26:13: warning: (near initialization for 'char_action[2][0]') [enabled by default]
post.c:26:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:26:13: warning: (near initialization for 'char_action[2][1]') [enabled by default]
post.c:26:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:26:13: warning: (near initialization for 'char_action[2][2]') [enabled by default]
post.c:26:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:26:13: warning: (near initialization for 'char_action[2][3]') [enabled by default]
post.c:27:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:27:13: warning: (near initialization for 'char_action[3][0]') [enabled by default]
post.c:27:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:27:13: warning: (near initialization for 'char_action[3][1]') [enabled by default]
post.c:27:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:27:13: warning: (near initialization for 'char_action[3][2]') [enabled by default]
post.c:27:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:27:13: warning: (near initialization for 'char_action[3][3]') [enabled by default]
post.c:28:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:28:13: warning: (near initialization for 'char_action[4][0]') [enabled by default]
post.c:28:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:28:13: warning: (near initialization for 'char_action[4][1]') [enabled by default]
post.c:28:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:28:13: warning: (near initialization for 'char_action[4][2]') [enabled by default]
post.c:28:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:28:13: warning: (near initialization for 'char_action[4][3]') [enabled by default]
post.c:29:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:29:13: warning: (near initialization for 'char_action[5][0]') [enabled by default]
post.c:29:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:29:13: warning: (near initialization for 'char_action[5][1]') [enabled by default]
post.c:29:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:29:13: warning: (near initialization for 'char_action[5][2]') [enabled by default]
post.c:29:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:29:13: warning: (near initialization for 'char_action[5][3]') [enabled by default]
post.c:30:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:30:13: warning: (near initialization for 'char_action[6][0]') [enabled by default]
post.c:30:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:30:13: warning: (near initialization for 'char_action[6][1]') [enabled by default]
post.c:30:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:30:13: warning: (near initialization for 'char_action[6][2]') [enabled by default]
post.c:30:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:30:13: warning: (near initialization for 'char_action[6][3]') [enabled by default]
post.c:31:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:31:13: warning: (near initialization for 'char_action[7][0]') [enabled by default]
post.c:31:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:31:13: warning: (near initialization for 'char_action[7][1]') [enabled by default]
post.c:31:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:31:13: warning: (near initialization for 'char_action[7][2]') [enabled by default]
post.c:31:13: warning: initialization from incompatible pointer type [enabled by default]
post.c:31:13: warning: (near initialization for 'char_action[7][3]') [enabled by default]
post.c:34:5: warning: unused variable 'char_new_state' [-Wunused-variable]
post.c:23:12: warning: unused variable 'char_action' [-Wunused-variable]
propeller-load -s cmm/post.elf
propeller-elf-objdump -h cmm/post.elf
Done. Build Succeeded!


propeller-load -S1 -Dreset=dtr -I /opt/parallax/propeller-load/ cmm/post.elf -r -p /dev/cu.usbserial-004213FAPropeller Version 1 on /dev/cu.usbserial-004213FA
Loading cmm/post.elf to hub memory
2268 bytes sent


Verifying RAM ... 
OK
Is there a better way to initialize a function pointer array at compile time that does not generate all these warning messages? Or is there a way to turn off warnings for just one file? I like to keep warnings on while I am developing.

Thanks.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-12-23 07:22
    Mark Mara wrote: »
    Is there a better way to initialize a function pointer array at compile time that does not generate all these warning messages?
    Wrt warning messages, you could start by actually matching the type of the functions, i.e. ACTION_PTR is defined to return void whereas all your functions (placed in the ACTION_PTR array) return int.
  • Mark MaraMark Mara Posts: 64
    edited 2013-12-23 07:27
    Thanks -markM
Sign In or Register to comment.