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

最近总是遇到关于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 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值