【问题标题】:How to use __func__ in 8051如何在 8051 中使用 __func__
【发布时间】:2022-01-17 10:38:16
【问题描述】:

我正在尝试在 8051 项目中使用 __func__ 宏打印函数名称。 但是当我在 Keil 上构建时,它会出现这样的错误:

main.c(50): error C202: '__func__': undefined identifier

有其他类似的宏吗? 请帮我解决。

【问题讨论】:

  • __func__ 是 C99 功能,因此它依赖于编译器来支持它。与8051无关
  • 8051 是 1980 年代的技术。为其设计的编译器不太可能与标准 C 保持同步。考虑切换到 40 岁以下且大部分已过时的 MCU 内核。
  • @Lundin 有开源的SDCC,它支持 C99 并为 8051 编译代码。事实上,有更老的 MCU/CPU 有一个活跃的社区,比如 Z80
  • @phuclv 不过,出于对 2021 年专业产品开发的怀旧之情,需要将考古学和逆向计算区分开来。显然,在业余爱好者的逆向计算环境中使用 8051 和 Z80 并没有错。

标签: c keil 8051


【解决方案1】:

正如documentation 所说,Keil C51 编译器不支持这个宏,而且显然没有其他类似的功能:

Cx51 编译器提供以下预定义常量,您可以在预处理器指令和 C 代码中使用这些常量来创建可移植程序。

Constant Description
__C51__ Version number of the compiler (for example, 701 for version 7.01).
__CX51__ Version number of the compiler (for example, 701 for version 7.01).
__DATE__ Date when the compilation was started in ANSI format (month dd yyyy).
__DATE2__ Date when the compilation was started in short form (mm/dd/yy).
__FILE__ Name of the file being compiled.
__LINE__ Current line number in the file being compiled.
__MODEL__ Memory model selected:
0 for SMALL,
1 for COMPACT,
2 for LARGE.
__TIME__ Time when the compilation was started. (Format: hh:mm:ss)
__STDC__ Defined to 1 to indicate full conformance with the ANSI C Standard.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-27
    • 2022-01-18
    • 2020-08-16
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多