Skip to content

translate-c: Function-local extern variable is missing namespace qualifier #20828

@linusg

Description

@linusg

Zig Version

0.14.0-dev.577+3344ed8b8

Steps to Reproduce and Observed Behavior

static inline CFNT_s* fontGetSystemFont(void)
{
	extern CFNT_s* g_sharedFont;
	if (!g_sharedFont)
		fontEnsureMapped();
	return g_sharedFont;
}

(https://github.com/devkitPro/libctru/blob/faf5162b60eab5402d3839330f985b84382df76c/libctru/include/3ds/font.h#L168-L174)

gets translated as

pub fn fontGetSystemFont() callconv(.C) [*c]CFNT_s {
    const ExternLocal_g_sharedFont = struct {
        extern var g_sharedFont: [*c]CFNT_s;
    };
    _ = &ExternLocal_g_sharedFont;
    if (!(g_sharedFont != null)) {
        _ = fontEnsureMapped();
    }
    return ExternLocal_g_sharedFont.g_sharedFont;
}

which doesn't build:

error: use of undeclared identifier 'g_sharedFont'
    if (!(g_sharedFont != null)) {
          ^~~~~~~~~~~~

Expected Behavior

         extern var g_sharedFont: [*c]CFNT_s;
     };
     _ = &ExternLocal_g_sharedFont;
-    if (!(g_sharedFont != null)) {
+    if (!(ExternLocal_g_sharedFont.g_sharedFont != null)) {
         _ = fontEnsureMapped();
     }
     return ExternLocal_g_sharedFont.g_sharedFont;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviortranslate-cC to Zig source translation feature (@cImport)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions