关于单片机的一些C语言使用

版权声明:提供模块,IoT清道者免费帮你模块级开发,只需你同意清道者将开发过程和源码发布在该微博上,需要的请在下方评论 https://blog.csdn.net/alingbo/article/details/81299752

最近总是遇到关于C语言的一些对于内存的处理,现总结如下:

(1)#pragma pack(4)

struct One{

   double d;

    char c;

   int i;

}

struct Two{

 char c;

 double d;

int i;

}

(2)__attribute__函数的作用:将数组定义在固定的flash空间上。

#if defined (__CC_ARM )
    uint8_t  m_dfu_settings_buffer[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_SETTINGS_ADDRESS)))
                                                   __attribute__((used));
#elif defined ( __GNUC__ )
    uint8_t m_dfu_settings_buffer[CODE_PAGE_SIZE] __attribute__ ((section(".bootloaderSettings")))
                                                  __attribute__((used));
#elif defined ( __ICCARM__ )
    __no_init __root uint8_t m_dfu_settings_buffer[CODE_PAGE_SIZE] @ BOOTLOADER_SETTINGS_ADDRESS;
#else
    #error Not a valid compiler/linker for m_dfu_settings placement.
#endif

其中#if defined ( __CC_ARM )、defined ( __ICCARM__ )以及defined ( __GNUC__ )

是因为ARM 系列目前支持三大主流的工具链:

ARM RealView (armcc)              =>ARM keil/MDK

IAR EWARM (iccarm)                =>IAR

GNU Compiler Collection (gcc) =>GCC

   例如在core_cm3.h中有如下定义:

    /* define compiler specific symbols */

  #if defined ( __CC_ARM )

     #define __ASM __asm /*!< asm keyword for armcc */

     #define __INLINE __inline /*!< inline keyword for armcc */

 #elif defined ( __ICCARM__ )

     #define __ASM __asm /*!< asm keyword for iarcc */

     #define __INLINE inline /*!< inline keyword for iarcc. Only

                                   avaiable in High optimization mode! */

     #define __nop __no_operation /*!< no operation intrinsic in iarcc */

 #elif defined ( __GNUC__ )

     #define __ASM asm /*!< asm keyword for gcc */

     #define __INLINE inline /*!< inline keyword for gcc

 #endif 

猜你喜欢

转载自blog.csdn.net/alingbo/article/details/81299752