Browser Support Test — C source
Audit your real browser against 30 modern web capabilities - WebGPU, WASM, WebAuthn, Service Workers and more. Get a weighted readiness score, copy-paste detection snippets, and a shareable link.
This is the C implementation — the same logic the interactive tool runs, in a shareable, citable form.
/* browser-support-test — C polyglot showcase port.
*
* Runtime capability probe, weighted score, and support tier.
*
* This is the C sibling of src/tools/BrowserSupportTest.tsx (+ the
* browser-support modules) that powers the live tool.
*
* ILLUSTRATIVE PORT: the live tool detects *browser* features at runtime
* (navigator/window probes) — a browser-only concern that cannot run in a
* native C process. This port shows the ANALOGOUS pattern for C: probes read
* predefined preprocessor macros (architecture, OS, CPU features, C11
* library gates) — the mechanism C uses to gate platform code, and the
* direct equivalent of `'feature' in window`. The scoring algorithm and
* tier thresholds below are byte-for-byte the same as the TypeScript lib's;
* only the probe targets differ.
*
* Language: C (C11, standard library only).
* Ported from src/tools/BrowserSupportTest.tsx (+ the browser-support modules).
* Source: CosmoDev polyglot showcase port.
* License: display source — part of CosmoDev's polyglot tool pages.
*/
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
static const char *const SUPPORTED = "supported";
static const char *const LIMITED = "limited";
static const char *const UNSUPPORTED = "unsupported";
static const char *const UNKNOWN = "unknown";
/* One capability the audit can check. `probe` returns true when the
capability is present in THIS build. */
typedef struct {
const char *id;
const char *title;
const char *category;
double weight;
bool (*probe)(void);
} Check;
/* Outcome of one probe. */
typedef struct {
const char *id;
const char *status;
} FeatureResult;
/* A support tier: display label + tone class. */
typedef struct {
const char *label;
const char *tone;
} Tier;
/* contribution × weight. Same values as src/tools/browser-support/score.ts. */
static double contribution(const char *status)
{
if (strcmp(status, "supported") == 0) return 1.0;
if (strcmp(status, "limited") == 0) return 0.5;
if (strcmp(status, "needs-https") == 0) return 0.3;
return 0.0; /* unsupported, unknown */
}
static const Check *find_check(const Check *catalog, size_t n, const char *id)
{
for (size_t i = 0; i < n; i++) {
if (strcmp(catalog[i].id, id) == 0) return &catalog[i];
}
return NULL;
}
/* Weighted readiness 0–100; matches computeScore() exactly. Results whose
id isn't in the catalog are ignored. */
static int compute_score(const FeatureResult *results, size_t n_results,
const Check *catalog, size_t n_checks)
{
double earned = 0.0;
double possible = 0.0;
for (size_t i = 0; i < n_results; i++) {
const Check *c = find_check(catalog, n_checks, results[i].id);
if (c == NULL) continue;
earned += contribution(results[i].status) * c->weight;
possible += c->weight;
}
if (possible == 0.0) return 0;
return (int)(earned / possible * 100.0 + 0.5); /* round half up (values ≥ 0) */
}
/* tier_for mirrors tierFor() in the island — same thresholds. */
static Tier tier_for(int score)
{
if (score >= 90) return (Tier){"Fully modern", "text-success"};
if (score >= 75) return (Tier){"Very capable", "text-success"};
if (score >= 55) return (Tier){"Capable, minor gaps", "text-accent"};
if (score >= 35) return (Tier){"Showing its age", "text-fg-muted"};
return (Tier){"Legacy browser", "text-danger"};
}
/* Probes. Predefined macros are resolved at compile time from the target
toolchain — C's equivalent of Rust's cfg!() / the browser's
`'feature' in window`. */
static bool probe_64bit(void)
{
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || \
defined(__LP64__) || defined(_LP64) || defined(_WIN64)
return true;
#else
return false;
#endif
}
static bool probe_unix(void)
{
#if defined(__unix__) || defined(__APPLE__)
return true;
#else
return false;
#endif
}
static bool probe_sse2(void)
{
#if defined(__SSE2__) || defined(_M_X64) /* SSE2 is baseline on x86-64 */
return true;
#else
return false;
#endif
}
static bool probe_avx2(void)
{
#if defined(__AVX2__)
return true;
#else
return false;
#endif
}
static bool probe_neon(void)
{
#if defined(__ARM_NEON) || defined(__ARM_NEON__)
return true;
#else
return false;
#endif
}
static bool probe_atomics(void)
{
/* C11 <stdatomic.h>: absent only when the implementation defines the opt-out. */
#if defined(__STDC_NO_ATOMICS__)
return false;
#else
return true;
#endif
}
static bool probe_threads(void)
{
#if defined(__STDC_NO_THREADS__)
return false;
#else
return true;
#endif
}
/* Representative catalog of macro-gated capabilities. */
static const Check checks[] = {
{"ptr-64", "64-bit pointers", "Platform", 1.0, probe_64bit},
{"unix", "Unix target", "Platform", 2.0, probe_unix},
{"sse2", "SSE2", "Cpu", 2.0, probe_sse2},
{"avx2", "AVX2", "Cpu", 2.0, probe_avx2},
{"neon", "NEON", "Cpu", 2.0, probe_neon},
{"atomics", "C11 atomics", "Runtime", 3.0, probe_atomics},
{"threads", "C11 threads", "Runtime", 2.0, probe_threads},
};
#define CHECKS_COUNT (sizeof checks / sizeof checks[0])
/* Run probes. C has no exceptions to catch — probes are total functions
(they cannot throw), so every check lands on supported/unsupported and
the references' degrade-to-'unknown' arm has nothing to intercept. */
static void run_checks(const Check *catalog, size_t n, FeatureResult *out)
{
for (size_t i = 0; i < n; i++) {
out[i].id = catalog[i].id;
out[i].status = catalog[i].probe() ? SUPPORTED : UNSUPPORTED;
}
}
static const char *host_os(void)
{
#if defined(__APPLE__)
return "macOS";
#elif defined(_WIN32)
return "Windows";
#elif defined(__linux__)
return "Linux";
#elif defined(__unix__)
return "Unix";
#else
return "unknown";
#endif
}
int main(void)
{
FeatureResult results[CHECKS_COUNT];
run_checks(checks, CHECKS_COUNT, results);
int score = compute_score(results, CHECKS_COUNT, checks, CHECKS_COUNT);
Tier tier = tier_for(score);
size_t supported = 0;
for (size_t i = 0; i < CHECKS_COUNT; i++) {
if (results[i].status == SUPPORTED) supported++;
}
printf("browser-support-test (C11) on %s\n", host_os());
printf("%zu/%zu capabilities · readiness %d · %s\n",
supported, (size_t)CHECKS_COUNT, score, tier.label);
/* Silence unused warning when LIMITED is intentionally absent from probes. */
(void)LIMITED;
(void)UNKNOWN;
return 0;
}
Also available in 13 other languages
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →