错误:在 MDK ARM uVision v5 ARM Compiler 5 中使用 __align() 时,此处可能未指定存储类

问题描述

我正在将一个项目从 CubeIDE (GCC) 迁移到针对基于 Arm® 的微控制器的最全面的软件开发解决方 uVision(ARM 编译器 5)并且在使用 __align 关键字时遇到困难.

在 CubeIDE 中编译良好的 CubeIDE 代码

#include <stdalign.h> 
typedef struct {
    volatile alignas(uint32_t) uint16_t imageDark[320]; 
} test_results;

一个问题是 uVision 无法定位 ,即 part of standard library of the C programming language

..\Src\device_tests.c(3): error:  #5: cannot open source input file "stdalign.h": No such file or directory

所以我删除 并基于 these KEIL documentation 将我的代码重写为

typedef struct {
         volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];
} test_results;

现在我收到以下错误

..\Src\device_tests.c(46): error:  #80: a storage class may not be specified here
    volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];
..\Src\device_tests.c(46): error:  #328: invalid storage class for a class member
    volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];

任何有关如何在 uVision 中进行对齐工作的帮助将不胜感激。

解决方法

我发现问题在于我试图在结构内对齐。上述语法适用于结构外的变量。但是为了让它在 struct 内工作,我使用了以下语法:

typedef struct {
     volatile uint16_t imageDark[320] __attribute__((aligned (4)));
} test_results;