Jump to content

Tony

EstablishedMember
  • Content count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Tony

  • Rank
    Newbrie

Profile Information

  • Gender
    Male
  • Location
    Christchurch, New Zealand
  1. Hi - I'm using SB C v6.97 compiling for a PIC16F1933. I have written an implementation of K&R's memory allocator but it seems to have an issue with pointer arithmetic, and throws the following errors: File is attached. ..\util.c(57): error: illegal operation for operands 'unsigned char' and 'header*' ..\util.c(57:4): error: failed to generate expression ..\util.c(91:9): error: failed to generate expression ..\util.c(91:9): error: invalid operand '+ ' ..\util.c(91:20): error: failed to generate expression ..\util.c(101:8): error: failed to generate expression ..\util.c(101:8): error: invalid operand '+ ' ..\util.c(101:19): error: failed to generate expression ... I have tried simplifying some of the expressions but to no avail. Cheers, Tony. util.c
  2. You are correct, accepted syntax doesn't appear to be as one would expect, I've added it to our bug list to get fixed. You can ignore this warning. It just means that the debug file (coff file) can't represent the function pointer data type. All this means is that you won't be able to watch the pointer values in the debugger. The way function pointers are implemented in BoostC is that the function pointer has a simple value, that value is an index into a jump table where the function arguments are patched, then the actual function is called. On return the return value is patched up and then the code returns to the caller. So what you see for each function pointer being a number that start at 1 and increases is what would you should get. Regards Dave Hi Dave - Excellent explanation, thanks Dave. I'll let you know how it goes once I get it loaded onto a target. Cheers, Tony.
  3. Hi Dave - Thanks again for your help. Dropping the brackets made my code compile, although this is not how K & R describe using function pointers. I'm still getting the warnings mentioned before, though, "Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x10000BBD" and looking at the assembler generated I am not confident the correct values are being written into the array for the function pointers. I can see the ASCII for the strings and the string terminator followed by a single byte that increases in value (from 0x01) for each entry in the array. Any idea what might be causing this, or at least, what it means? Cheers, Tony.
  4. You have probably done made the same mistake I did when trying to compile your code: #define CMD_STR_MAX_LEN 1; typedef struct cmd_S { void ( *cmdFunc )( char * cmdLinePt ); char cmdStr[ CMD_STR_MAX_LEN ]; } cmdStruct; void main() { } Notice the mistake? There is a semi colon where it shouldn't be, at the end of "#define CMD_STR_MAX_LEN 1;". Removing that allows successful compilation for me. Regards Dave Hi Dave - Thanks for your reply. It turns out that this wasn't the problem (although I did remove it thanks ) because if I comment out the function pointer line in the structure then it compiles fine. I ended up fixing this by upgrading my compiler to version 6.97. This now compiles but has revealed another issue. Code snippets are below, full project is attached. In header: typedef struct cmd_S { char cmdStr[ CMD_STR_MAX_LEN ]; void ( *cmdFunc )( char * cmdLinePt ); } cmdStruct; In C file: cmdStruct commands[ CMD_NUM ] = { { "\1load", cmdLoad }, { "\1run", cmdRun }, { "\1stop", cmdStop }, { "\1dump", cmdDump }, { "\1clear", cmdClear }, { "\1erase", cmdErase }, { "\2blank", cmdBlank }, { "\2burn", cmdBurn }, { "\1verify", cmdVerify } }; //----------- cmdStruct * getCmd( char ** cmdLinePtPt ) { //-------- return &commands[ i ]; } void main( void ) { cmdStruct * command; //--------- command = getCmd( &cmdBuffPt ); if ( command != NULL ) { ( *command->cmdFunc )( cmdBuffPt ); } } The last line above produces an "error: missing semicolon" error. If this line is commented out the code compiles, but produces the following warnings: Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x10000BBD Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x10000BBD Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x10000F9D Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x10000F9D Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x100010F1 Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x100010F1 Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x100012B6 Coff generation: Internal Warning: Member Var:cmdFunc Unrecognised type id:0x100012B6 I have attached my project snapshot if you need it; the AROStdTypes.h should be placed in the 'include' folder. There must be something fundamentally wrong with the way I am trying to do function pointers. Functionally, the user enters a command into main, getCmd then searches the commands array for the command string and returns the address of the array element found. The main function then calls the returned command function via the pointer stored in the array. At least this is what's supposed to happen! Cheers, Tony O'Brien. ROMSIM_01_110823.zip
  5. Hi - I am running an older version of BoostC (v.6.81) as this is what my work has purchased. I am trying to add a function pointer to a structure but the compiler gives a "Missing right brace" error. As far as I can see there is nothing wrong with the code. Is this a limitation with this version of the compiler? The manual says "pointers can be used in the standard way". The code below is situated in a header file. typedef struct cmd_S { void ( *cmdFunc )( char * cmdLinePt ); char cmdStr[ CMD_STR_MAX_LEN ]; } cmdStruct; Cheers, Tony.
×