This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430F5310: Moved MSP430 pjt from compiler 4.4.2 to 16.9.1, Now I get error badly formed pragma

Part Number: MSP430F5310

Tool/software: TI C/C++ Compiler

I migrated my MSP430F5310 project from CCS 5.5 to CCS 6.2, compiler 4.4.2 to 16.9.1 respectively.

Now I am getting the error #821 badly formed pragma.

Although the function call has changed, this pragma worked in the code compiled by compiler v4.4.2:

#pragma CODE_SECTION (WriteToFlash, "WRITETOFLASH_SEG")
unsigned char Write_To_Flash(unsigned char* src, unsigned char* dst, unsigned int size)
{
    return CFlashLogic_MSP430_5xx_6xx::WriteToFlash(src, dst, size);
}

 

Can anyone shed any light on this?

Jim

  • This line ...

    Jim Cook said:
        return CFlashLogic_MSP430_5xx_6xx::WriteToFlash(src, dst, size);

    ... tells me this is C++ code.  The syntax name::something only occurs in C++.

    In C++, the CODE_SECTION pragma does not explicitly name the function.  It always applies to the next function defined.  You have to write it ...

    #pragma CODE_SECTION ("WRITETOFLASH_SEG")

    This has always been the case.  Thus, I understand why this line fails with the recent compiler.  I don't understand how it ever worked with the older compiler.

    Thanks and regards,

    -George

  • George,

    Thanks for the reply.

    I made a mistake in my post. I have enclosed the C++ class-call (that was incorrectly shown in the #pragma in my previous post) in a C-style-wrapper.

    In my previous post I had the C++ function call in the #pragma, but that was an error in the post on my part.

    The actual #pragma has the C-style-wrapper name in it, not the C++ call.

    However, that C-style-wrapper is still defined inside of a C++ file. I tried prototyping the function as extern "C" but either way, I still got the error.

    I did as you suggested and  removed the function call name and it compiled.

    -------------------------------------------------------------------

       ***** ERROR ********

    #pragma CODE_SECTION (Write_To_Flash, "WRITETOFLASH_SEG")

    unsigned char Write_To_Flash(unsigned char* src, unsigned char* dst, unsigned int size)

    {

       return CFlashLogic_MSP430_5xx_6xx::WriteToFlash(src, dst, size);

    }

       ***** COMPILES *****

    #pragma CODE_SECTION ("WRITETOFLASH_SEG")

    unsigned char Write_To_Flash(unsigned char* src, unsigned char* dst, unsigned int size)

    {

       return CFlashLogic_MSP430_5xx_6xx::WriteToFlash(src, dst, size);

    }

     

    -------------------------------------------------------------------

     >> [George] In C++, the CODE_SECTION pragma does not explicitly name the function.

    >> [George] I don't understand how it ever worked with the older compiler.

    -------------------------------------------------------------------

     

    Well, I think you hit the nail on the head. The older code was C-code. I mentioned that the call had changed. What I didn't make clear is that I also migrated this part of the program to C++. In hindsight, probably NOT a good detail to leave out !!! In C the function name is provided in the #pragma.

    I'm still curious as to why extern "C" in the header file did not fix using the C-style #pragma format?

    I guess that is because it is still compiled by the C++ compiler, only the name-mangling is changed?

    Thanks,
    Jim

  • Jim Cook said:

    I'm still curious as to why extern "C" in the header file did not fix using the C-style #pragma format?

    I guess that is because it is still compiled by the C++ compiler, only the name-mangling is changed?

    Thanks,

    That's correct.  An extern "C" block only disables the mangling of function names.  Otherwise, it's as much C++ as anything else in the file.

    Thanks and regards,

    -George