{"slug": "raylib-6-2-ported-to-zig-with-every-example-checked-against-c-now-running-in-the", "title": "Raylib 6.2 ported to Zig, with every example checked against C (now running in the browser too)", "summary": "A developer has ported raylib 6.2 to Zig, checking every example against the original C version and running the library in the browser via WebAssembly. The port is a direct C-to-Zig translation that calls libc functions such as fopen, fread and memcpy through extern declarations rather than using Zig's optionals, error unions and allocators, and commenters criticized it as \"C code written with Zig keywords\" that could teach bad habits.", "body_md": "\n\n``` js\n// stdio FILE handling via opaque pointer\nconst FILE = anyopaque;\nextern fn fopen([*c]const u8, [*c]const u8) ?*FILE;\nextern fn fclose(?*FILE) c_int;\nextern fn fseek(?*FILE, c_long, c_int) c_int;\nextern fn ftell(?*FILE) c_long;\nextern fn fread(?*anyopaque, usize, usize, ?*FILE) usize;\nextern fn fwrite(?*const anyopaque, usize, usize, ?*FILE) usize;\nextern fn fprintf(?*FILE, [*c]const u8, ...) c_int;\nextern fn fgets([*c]u8, c_int, ?*FILE) [*c]u8;\nextern fn feof(?*FILE) c_int;\nextern fn sscanf([*c]const u8, [*c]const u8, ...) c_int;\nconst SEEK_SET: c_int = 0;\nconst SEEK_END: c_int = 2;\n```\n\n…directly calling into clib doesn’t look very Ziggy to me\n\nAlso tbh, what’s the point. The code is pretty much a straight translation from C to Zig without taking any advantage of Zig’s language features (optionals, error results, allocators, etc etc…), I’m sure Claude could do better…\n\nAlso… hrmpf look at all those C string.h and memory.h functions…\n\n```\n            if ((strcmp(&dp.name, \".\") != 0) and (strcmp(&dp.name, \"..\") != 0)) {\n                const pathLength = snprintf(&path, MAX_FILEPATH_LENGTH, \"%s/%s\", basePath, &dp.name);\n                if ((pathLength < 0) or (pathLength >= MAX_FILEPATH_LENGTH)) {\n                    TraceLog(LOG_WARNING, \"FILEIO: Path longer than %d characters (%s...)\", @as(c_int, MAX_FILEPATH_LENGTH), basePath);\n                } else if (IsPathFile(&path)) {\n                    if ((filter == null) or (strstr(filter, FILE_FILTER_TAG_ALL) != null) or (strstr(filter, FILE_FILTER_TAG_FILE_ONLY) != null) or IsFileExtension(&path, filter)) {\n                        _ = memcpy(@ptrCast(files.paths[files.count]), @ptrCast(&path), @intCast(pathLength));\n                        files.count += 1;\n                    }\n                } else {\n                    if ((filter != null) and ((strstr(filter, FILE_FILTER_TAG_DIR_ONLY) != null) or (strstr(filter, FILE_FILTER_TAG_ALL) != null))) {\n                        _ = memcpy(@ptrCast(files.paths[files.count]), @ptrCast(&path), @intCast(pathLength));\n                        files.count += 1;\n                    }\n                    if (scanSubdirs) ScanDirectoryFiles(&path, files, filter, expectedFileCount, scanSubdirs);\n                }\n```\n\nThis is built for me and my team as a learning exercise for zig\n\nI don’t think you’re doing yourself a favour with this approach. This is C code written with Zig keywords, not Zig code. E.g. you’re kinda missing the forest for the trees and you might just learn bad habits from this codebase.", "url": "https://wpnews.pro/news/raylib-6-2-ported-to-zig-with-every-example-checked-against-c-now-running-in-the", "canonical_source": "https://ziggit.dev/t/raylib-6-2-ported-to-zig-with-every-example-checked-against-c-now-running-in-the-browser-too/17986#post_2", "published_at": "2026-10-16 13:25:59+00:00", "updated_at": "2026-10-16 13:47:05.096873+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["raylib", "Zig", "C", "Claude"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/raylib-6-2-ported-to-zig-with-every-example-checked-against-c-now-running-in-the", "markdown": "https://wpnews.pro/news/raylib-6-2-ported-to-zig-with-every-example-checked-against-c-now-running-in-the.md", "text": "https://wpnews.pro/news/raylib-6-2-ported-to-zig-with-every-example-checked-against-c-now-running-in-the.txt", "jsonld": "https://wpnews.pro/news/raylib-6-2-ported-to-zig-with-every-example-checked-against-c-now-running-in-the.jsonld"}}