objc/test/parserexpf_demo.m · 3155 字节 · 下载原文
// ⚠ 这一行 `extern` 是**普通 C 函数声明,不是 UI 库**(`parserexpf` 属 `Lib/shared/parserexpf.c`)。
// ⚠ This `extern` is a **plain C function declaration, not the UI library** (`parserexpf` lives in `Lib/shared/parserexpf.c`).
// 为什么不能换成一条 `#import`(2026-10-01 实测,不是没试):
// Why it cannot be replaced by an `#import` (measured 2026-10-01, not for lack of trying):
// · `Lib/c/shared_bindings.h`(**唯一**声明了 `parserexpf` 的头)在 ObjC 前端编不过:
// · `Lib/c/shared_bindings.h` (the **only** header declaring `parserexpf`) does not compile in the ObjC frontend:
// 先要 `#include <stddef.h>`(否则 `size_t`/`wchar_t` 不认识),再撞上 `int mutex_lock(int id)`
// it first needs `#include <stddef.h>` (else `size_t`/`wchar_t` are unknown), then hits `int mutex_lock(int id)`
// 那两个 `id` 形参 ⇒ `expected )(得到 IdType 'id')`。
// where `id` is a reserved type name ⇒ `expected ) (got IdType 'id')`.
// · `Lib/objc/shared.h`(ObjC 自己的绑定头)**通篇是注释**,不产生任何声明。
// · `Lib/objc/shared.h` (ObjC's own bindings header) is **comments only** and declares nothing.
// ⇒ 本仓目前**没有 ObjC 能用的 `parserexpf` 声明头**,这一行 `extern` 只能留着。
// ⇒ This repo currently has **no ObjC-usable declaration header for `parserexpf`**, so this `extern` stays.
// ✅ 2026-10-20 修好(原记录:本示例曾打印 `Float: 0.000000`):根因**不在返回值,在实参** ——
// 本地函数那条调用路用裸 `PUSH R0` 压实参(浮点在 F0/D0、double 占 8 字节)⇒ 被调方读到的第二个字是垃圾;
// 而「库函数返回 double」那条是**另一处**:原型 `extern double …;` 的返回类型被丢掉 ⇒ 调用点按 int 取 R0。
// 两处都补上之后本示例打印 `Float: 7.000000`(期望值)。
// ✅ Fixed 2026-10-20 (previously printed `Float: 0.000000`): the root cause was the **arguments**, not the return —
// local calls pushed them with a bare `PUSH R0` (floats live in F0/D0, doubles take 8 bytes); separately, a
// `double`-returning **prototype** lost its return type, so the call site read R0 as an int. Both fixed ⇒ `7.000000`.
// ⚠ 仍然成立(2026-10-20 复验):`Lib/c/shared_bindings.h` 在 ObjC 前端**仍然编不过**,
// ⚠ Still true (re-checked 2026-10-20): `Lib/c/shared_bindings.h` **still fails to compile** under the ObjC frontend,
// 但**首个拦路者换了**:现在是第 364 行的 `objc_count(int* self)`(`self` 是保留类型名 ⇒ `expected )(得到 Self 'self')`),不再是 `id`;`Lib/objc/shared.h` 仍是通篇注释。
// though **the first blocker changed**: it is now `objc_count(int* self)` at line 364 (`self` is a reserved type name ⇒ `expected ) (got Self 'self')`), no longer `id`; `Lib/objc/shared.h` is still comments-only.
#include <stdio.h>
extern double parserexpf(const char *e);
int main() { printf("Float: %f\n", parserexpf("2.5+3*1.5")); return 0; }