搜索
bottom↓
回复: 2

IAR EWARM 7.8 使用 __attribute__ 示例

[复制链接]

出0入0汤圆

发表于 2016-11-15 14:37:47 | 显示全部楼层 |阅读模式
相关文档找不到  __attribute__ 的用法, 写了一个测试文件编译通过。

  1. #include <stdint.h>
  2. uint32_t VarInSection __attribute__ ( (section (".Var")) );
  3. uint8_t AlignedArray[ 128 ] __attribute__( ( aligned( 128 ) ) );
  4. typedef struct
  5. {
  6.   uint8_t Var8a;
  7.   uint16_t Var16a __attribute__( ( aligned( 8 ) ) );
  8.   uint32_t Text[ 4 ];
  9. } AlignedMember_TypeDef;
  10. AlignedMember_TypeDef AlignedMember;
  11. typedef struct __attribute__( (packed) )
  12. {
  13.   uint8_t Var8a;
  14.   uint16_t Var16a;
  15.   uint32_t Text[ 4 ];
  16. } PackedStruct_TypeDef;
  17. PackedStruct_TypeDef PackedStruct;
  18. typedef struct
  19. {
  20.   uint8_t Var8a;
  21.   uint16_t Var16a;
  22.   uint32_t Text[ 4 ];
  23. } __attribute__( (packed) ) PackedStruct2_TypeDef;
  24. PackedStruct2_TypeDef PackedStruct2;
  25. typedef struct __attribute__( (packed,  aligned( 128 ) ) )
  26. {
  27.   uint8_t Var8a;
  28.   uint16_t Var16a;
  29.   uint32_t Text[ 4 ];
  30. } AlignedPackedStruct_TypeDef;
  31. AlignedPackedStruct_TypeDef AlignedPackedStruct;
  32. void Foo( void ) __attribute__ ( (section (".Foo")) );
  33. void Foo( void )
  34. {
  35.   VarInSection = 0;
  36.   AlignedArray[ 0 ] = 0;
  37.   PackedStruct.Text[ 0 ] = 1;
  38.   PackedStruct2.Text[ 0 ] = 1;
  39.   AlignedMember.Var16a = 0;
  40.   AlignedPackedStruct.Text[ 0 ] = 1;
  41. }
  42. // .textrw and .text
  43. __root __ramfunc void ramfunc0(void)
  44. {
  45. }
  46. // No effect : .ramfunc
  47. __root void ramfunc1(void) __attribute__ ( (section(".ramfunc") ) );
  48. __root void ramfunc1(void)
  49. {
  50.   ramfunc0();
  51. }
复制代码


列表文件部分内容

  1. *******************************************************************************
  2. *** PLACEMENT SUMMARY
  3. ***
  4. "A0":  place at 0x00000000 { ro section .intvec };
  5. "P1":  place in [from 0x00000000 to 0x0007ffff] { ro };
  6. "P3":  place in [from 0x00000000 to 0x00000000] |
  7.                 [from 0x20000000 to 0x2000ffff] {
  8.           rw, block CSTACK, block PROC_STACK, block HEAP };
  9. initialize by copy { rw };
  10.   Section               Kind        Address    Size  Object
  11.   -------               ----        -------    ----  ------
  12. "P1":                                        0x13a8
  13.   .ramfunc              ro code  0x0000133c     0x4  __attribute__.o [1]
  14.   .Foo                  ro code  0x00001218    0x2c  __attribute__.o [1]
  15. "P3", part 1 of 3:                             0xb0
  16.     .textrw             inited   0x200000ac     0x2  __attribute__.o [1]
  17. "P3", part 2 of 3:                           0x142c
  18.   .bss                  zero     0x20001280    0x80  __attribute__.o [1]
  19.   .bss                  zero     0x20001300    0x80  __attribute__.o [1]
  20.   .bss                  zero     0x200014c4    0x14  __attribute__.o [1]
  21.   .Var                  zero     0x200014d8     0x4  __attribute__.o [1]
  22.                                - 0x200014dc  0x142c
  23. *******************************************************************************
  24. *** ENTRY LIST
  25. ***
  26. Entry                      Address    Size  Type      Object
  27. ramfunc1                0x0000133d     0x4  Code  Gb  __attribute__.o [1]
  28. ramfunc0                0x200000ad     0x2  Code  Gb  __attribute__.o [1]
  29. AlignedArray            0x20001280    0x80  Data  Gb  __attribute__.o [1]
  30. AlignedPackedStruct     0x20001300    0x80  Data  Gb  __attribute__.o [1]
  31. Foo                     0x00001219    0x2c  Code  Gb  __attribute__.o [1]
  32. PackedStruct            0x200014c4    0x14  Data  Gb  __attribute__.o [1]
  33. VarInSection            0x200014d8     0x4  Data  Gb  __attribute__.o [1]
复制代码


阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2016-11-25 18:23:34 | 显示全部楼层
谢谢分享!收藏了!

出0入0汤圆

 楼主| 发表于 2017-10-19 14:42:50 | 显示全部楼层
IAR C/C++ Development Guide
Compiling and Linking for Advanced RISC Machines Ltd’s ARM® Cores

EDITION NOTICE
Twenty-second edition: March 2017
Part number: DARM-22
This guide applies to version 8.10.x of IAR Embedded Workbench® for ARM.
Internal reference: BB1, csrct2010.1, V_110411, IMAE.

=========================================================================

In extended language mode, the IAR C/C++ Compiler
also supports a limited selection of GCC-style attributes.

Use the __attribute__ ( (attribute-list) ) syntax for these attributes.

The following attributes are supported in part or in whole.
For more information, see the GCC documentation.

alias
aligned
always_inline
cmse_nonsecure_call
cmse_nonsecure_entry
deprecated
noinline
noreturn
packed
pcs (for IAR type attributes used on functions)
section
target (for IAR object attributes used on functions)
transparent_union
unused
used
volatile
weak

回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-3-29 03:06

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表