为什么我们在用于内存测试的模式末尾找到 ULL?

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

在为测试内存而编写的模式末尾添加 ULL 有什么用?

例如

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;
      }
    }
  }

它是一个后缀,表示整型字面量是一个 unsigned long long。

对于您的代码片段,它仅适用于 self-commenting 代码。

后缀llu用于显式指定整型常量的类型为unsigned long long

然而,当常量以十六进制表示法表示时,可以省略后缀,因为编译器本身确定常量的类型。即(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.

并且对于十六进制整数常量

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