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.

Error, CCS, MSP430, Assigning "const" or "volatile" Arrays to a "volatile const" Array Pointer



Hello,

I don't think what I am trying to do is wrong. It compiles in IAR without warning (although I am unable to verify MISRA checking in IAR). I get errors as shown in CCS.

#include "stdint.h"

volatile uint32_t Vol_Array[]   = {0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU};
const uint32_t Const_Array[]    = {0x12345678U, 0x87654321U, 0x17171717U, 0x26262626U, 0xa6a6a6a6U};

/* Create a pointer to an array of 5 volatile, constant long integers. */
volatile const uint32_t (*Aray_ptr)[5];

int main(void)
{
  /* Without applying a cast to the array address: */
  /* #515 a value of type "volatile uint32_t (*)[5]" cannot be assigned to an entity of type "const volatile uint32_t (*)[5]" */
  Aray_ptr = &Vol_Array;
  /* #515 a value of type "const uint32_t (*)[5]" cannot be assigned to an entity of type "const volatile uint32_t (*)[5]" */
  Aray_ptr = &Const_Array;
  
  /* With a cast applied to the array address: */
  /* #1402-D (MISRA-C:2004 11.5/R) A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer */
  Aray_ptr = (const volatile uint32_t (*)[5]) (&Vol_Array);
  /* #1402-D (MISRA-C:2004 11.5/R) A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer */
  Aray_ptr = (const volatile uint32_t (*)[5]) (&Const_Array);
  
  return 0;
}

  • nick43oh said:
    It compiles in IAR without warning

    There are few diagnostic which the compiler is required to emit, or not emit.  Thus this is an area where you should expect variance among compilers.  When I tried the GCC MSP430 compiler, it issues a warning similar to the one issued by the TI compiler. 

    It is a warning, and not an error.  You can ignore it if you want.  You can also disable it.  Look at the MSP430 presentation on this page, and look through the section titled Compiler Diagnostics.

    Thanks and regards,

    -George

  • Another way to learn about controlling compiler diagnostics is with this video.

    Thanks and regards,

    -George

  • Hi George,

    Thanks for your reply.
    I would still like to bring to your attention the MISRA errors raised when the casts are performed.
    The casts I used did not REMOVE any "const" or "volatile" qualifications, only added one or the other. I believe this to be a compiler bug.

    Thanks, Nick.
  • I overlooked the MISRA part of your post.  That does appear to be a compiler error.  I filed SDSCM00052358 in the SDOWP system to have this investigated.  You are welcome to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George