Search code examples
carmembeddedkeil

C is ignoring byte assignment?


Im doing something wrong.

This is the piece of code from ARM code (Keil5 IDE):

uint8_t * at_ss_data = (uint8_t *)("\n\rAT$SS=AA AA\n\r");
at_ss_data[12] = 0;

but the 12th index (the last A) does not change in the variable when the code is pushed to the ARM embedded board.

My goal is to change the AA AA substring in the at_ss_data array to 00 00


Solution

  • You must not modify a string literal (which is undefined behavior). You should use an array initialized with a string literal.

    This way, your code should be:

    uint8_t at_ss_data[] = "\n\rAT$SS=AA AA\n\r";
    at_ss_data[12] = 0;