cancel
Showing results for 
Search instead for 
Did you mean: 

syntax is the bane of my work...

T J
Lead

I don't understand why this would compile and work for one project but not another...

const char Menu[40][32] = { 
    "\033[91;2mShow Menu\033[93;2m <space>", 
    "\033[0m ",
    "1 Read Flash status"
};
 
    char * ptr = &Menu;    <- fails here

 [Clang IntelliSense] Warning: incompatible pointer types initializing 'char *' with an expression of type 'const char (*)[40][32]'   VS_EBrakes3F6   c:\users\nickm\documents\vs2018\ebrakesv3_f6\src\bios.c   1107   

4 REPLIES 4
RSonn
Associate II

I see a warning only. so compilation succeeded, I suppose. char * insn't const char *, so a warning is ok here. Perhaps in the other project compiler settings are more permissive with respect to warnings?​

T J
Lead

thanks for looking in,

yes, just a warning,

seems to work now, not sure what fixed it :(

but robust now...

Danish1
Lead II

Menu is an array of 40 constant C-strings, each with a maximum length of 32 characters.

You have set ptr to the address of Menu - so ptr should be the same type as Menu.

If you wanted to set ptr to point to the first string in Menu, then you should have said ptr = &Menu[0];

Do you elsewhere access Menu[1], ...?

Or to access the next menu-item, do you want to say ptr[1] or ++ptr? Because the C compiler would need to know that the size of the element pointed to by ptr is not 1 (sizeof(char)) but 32 (i.e. sizeof(char[32]) ) In which case ptr should be declared/initialised as const char (*ptr)[32] = &Menu;

There's the const-ness as well as mentioned by roland.sonnenschein

  • Danish
T J
Lead

I haven't seen this style before:

 const char (*ptr)[32]

is that the next ptr++ will point to the next string ? adding 32 byte count