硬汉嵌入式论坛

 找回密码
 立即注册
查看: 57|回复: 0
收起左侧

[MDK] Keil uVision V5.26.0.0 宏定义解析是否存在 bug?

[复制链接]

0

主题

4

回帖

4

积分

新手上路

积分
4
发表于 7 小时前 | 显示全部楼层 |阅读模式
本帖最后由 xbin 于 2026-5-29 16:01 编辑

keil 在 `Options for Target -> C/C++ -> Define` 处定义宏 CONFIG_A, CONFIG_FILE=\"config.h\", CONFIG_B
其中我发现 CONFIG_B 并没有被定义,好像是没有被解析出来。
如果 CONFIG_B 定义在 CONFIG_FILE=\"config.h\" 前面就没有问题
我看 mbedtls 中就是这种写法

[C] 纯文本查看 复制代码
// Middlewares/Third_Party/mbedTLS/include/mbedtls/build_info.h
/* X.509, TLS and non-PSA crypto configuration */
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/mbedtls_config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif


下面是测试用例:

[C] 纯文本查看 复制代码
#if defined(CONFIG_A)
int a[-1];
#endif

#include CONFIG_FILE

#if defined(CONFIG_B)
int b[-1];
#endif

int main() {    
    return 0;
}

/*
uVision V5.26.0.0

1. CONFIG_A, CONFIG_B, CONFIG_FILE=\"config.h\"

```txt
Build target 'A_B_FILE'
compiling main.c...
main.c(2): error:  #94: the size of an array must be greater than zero
  int a[-1];
main.c(8): error:  #94: the size of an array must be greater than zero
  int b[-1];
main.c: 0 warnings, 2 errors
".\Objects\keil_test.axf" - 2 Error(s), 0 Warning(s).
```


2. CONFIG_A, CONFIG_FILE=\"config.h\", CONFIG_B

```txt
Build target 'A_FILE_B'
compiling main.c...
main.c(2): error:  #94: the size of an array must be greater than zero
  int a[-1];
main.c: 0 warnings, 1 error
".\Objects\keil_test.axf" - 1 Error(s), 0 Warning(s).
```
*/




keil_test.rar

14.07 KB, 下载次数: 1

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2026-5-29 23:30 , Processed in 0.327370 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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