search

Home  >  Q&A  >  body text

c++ - 一段c代码没看明白

有一段freerots里面的代码,第3,4,5,7行我没看明白,有朋友能帮忙一下吗?尤其是那个“@”。

/* Allocate the memory for the heap. */
#if configUSE_HEAP_SECTION_NAME && configCOMPILER==configCOMPILER_ARM_IAR /* << EST */
  #pragma language=extended
  #pragma location = configHEAP_SECTION_NAME_STRING
  static uint8_t ucHeap[configTOTAL_HEAP_SIZE] @ configHEAP_SECTION_NAME_STRING;
#elif configUSE_HEAP_SECTION_NAME
  static uint8_t __attribute__((section (configHEAP_SECTION_NAME_STRING))) ucHeap[configTOTAL_HEAP_SIZE];
#else
static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#endif
PHPzPHPz2767 days ago599

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:08:48

    First of all, I won’t talk about the conditional compilation of #if.
    #pragma and __atribute__ are both compiler preprocessing commands.
    #pragma location and the following sentence are preprocessing commands related to the IAR compiler. The purpose of these two sentences is to place the array ucHeap at a specified address. The basic syntax is, #pragam location=地址 and 变量 @ 地址. For specific syntax, see http://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_DevelopmentGuide.ENU.pdf "Controlling data and function placement in memory" (page 218) That section
    __attribute__ section means to put this array into the specified section. This is a compilation attribute of the GNU compiler.

    So the meaning of this code is to define an array ucHeap and then determine whether to specify the address of this array according to the configuration

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:08:48

    These should be the extended functions and syntax of the compiler, especially the #pragma and __attribute__. Check what platform code this is, what compiler is used, and then check the compiler documentation

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:08:48

    You can put the variables together in a section. For example, if frequently accessed data is placed together, caching will be more effective.

    reply
    0
  • Cancelreply