Search code examples
cmemory-managementconstantserror-checking

why we found ULL in the end of patterns used for memory testing?


What is the utility of adding ULL in the end of patterns written to test the memory ?

For Exemple

uint64 pattern_55 =  0xAAAAAAAAAAAAAAAAULL;

static error_t  sram_aa_55_test(uint32 start_address, uint32 tested_area_size)
  {
    error_t status = E_NOERROR;

          /*Patterns used to test every SRAM cell */
    uint64 pattern_aa = 0x5555555555555555ULL;
    uint64 pattern_55 = 0xAAAAAAAAAAAAAAAAULL;

          /* Current address being tested */
    uint32 address;

          /* data read back in memory */
    uint64 data_read;

          /* AA pattern test */
    memset((uint64*)start_address, pattern_aa, tested_area_size);
    sync();

    for (address = start_address; address < start_address + tested_area_size; address += sizeof(uint64))
    {
            /* read back the memory cell and check that it contains the same pattern we just wrote */
      data_read = rd_io_64(address);

      if (data_read != pattern_aa)
      {
        return CORE_Test_Error;
      }
    }
  }

Solution

  • In case of your code snippet it is only for self-commenting the code.

    The suffux llu is used for explicit specifying that an integer constant has the type unsigned long long.

    However when a constant is presented in the hexadecimal notation the suffix can be omitted because the compiler itself determines the type of the constant. That is (The C Standard, 6.4.4.1 Integer constants)

    5 The type of an integer constant is the first of the corresponding list in which its value can be represented.

    And for hexadecimal integer constants

    int
    unsigned int
    long int
    unsigned long int
    long long int
    unsigned long long int