CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 15:58:30 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"ccbbcd5794d91ea0ea911061fa3d8171"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=WfWolZDxevqEFP5qwe%2Bq8IoxOfIh8QMCGJ34MaXiftSvURSKgW%2BkN3fUiC7qc5%2Bq3U6yiZYfXUqNYZoXSgFd5FiZaZBdfTGFw0p2AnbxoKA6x9fFursrtdto8I4yXq6oBtkNAPy2ZuxSvzjI7h5rfH99chgVTSr5tOHCmn87xzM4X9qVvAuEVPgfNgcLNINAZTLJ3RUB5U4JMrXMkpLUR3F8VDh22Y9gbFVSSkg8P%2FPdWTHSNzeMd4JCq3zK8sTfQ0bbJop1KjemUeEuVtrNJw%3D%3D--k%2FoMqXYAi4MSuqIc--YYWnhSf0LKrQmubf3b1JIA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.336712381.1760198310; Path=/; Domain=github.com; Expires=Sun, 11 Oct 2026 15:58:30 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 11 Oct 2026 15:58:30 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: B9A4:1FDE52:847768:ADE65F:68EA7EA6
N3037 showcase · GitHub
Show Gist options
Save skeeto/3fe27cd81ca5bdb4926b12e03bdfbc62 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
-
Star
3
(3)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save skeeto/3fe27cd81ca5bdb4926b12e03bdfbc62 to your computer and use it in GitHub Desktop.
N3037 showcase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requires GNU C23: GCC >= 15 or Clang >= 21 | |
#include <stddef.h> | |
#include <string.h> | |
#define affirm(c) while (!(c)) unreachable() | |
#define lenof(a) (iz)(sizeof(a) / sizeof(*(a))) | |
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t)) | |
#define maxof(t) ((t)-1<1 ? (((t)1<<(sizeof(t)*8-2))-1)*2+1 : (t)-1) | |
#define S(s) (Str){(u8 *)s, lenof(s)-1} | |
typedef unsigned char u8; | |
typedef int b32; | |
typedef int i32; | |
typedef long long i64; | |
typedef typeof((u8*)0-(u8*)0) iz; | |
typedef typeof(sizeof(0)) uz; | |
typedef struct { | |
u8 *beg; | |
u8 *end; | |
} Arena; | |
static void *alloc(Arena *a, iz count, iz size, iz align) | |
{ | |
iz pad = -(uz)a->beg & (align - 1); | |
affirm(count < (a->end - a->beg - pad)/size); | |
u8 *r = a->beg + pad; | |
a->beg += pad + count*size; | |
return memset(r, 0, count*size); | |
} | |
typedef struct { | |
u8 *data; | |
iz len; | |
} Str; | |
static Str span(u8 *beg, u8 *end) | |
{ | |
affirm(beg <= end); | |
return (Str){beg, end-beg}; | |
} | |
static Str slice(Str s, iz beg, iz end) | |
{ | |
affirm(beg >= 0 && end <= s.len); | |
return span(s.data+beg, s.data+end); | |
} | |
#define Slice(T) \ | |
struct Slice##T { \ | |
T *data; \ | |
iz len; \ | |
iz cap; \ | |
} | |
#define push(a, s) \ | |
((s)->len == (s)->cap \ | |
? (s)->data = push_( \ | |
(a), \ | |
(s)->data, \ | |
&(s)->cap, \ | |
sizeof(*(s)->data), \ | |
_Alignof(typeof(*(s)->data)) \ | |
), \ | |
(s)->data + (s)->len++ \ | |
: (s)->data + (s)->len++) | |
static void *push_(Arena *a, void *data, iz *pcap, iz size, iz align) | |
{ | |
iz cap = *pcap; | |
if (a->beg != (u8 *)data + cap*size) { | |
void *copy = alloc(a, cap, size, align); | |
memcpy(copy, data, cap*size); | |
data = copy; | |
} | |
iz extend = cap ? cap : 4; | |
alloc(a, extend, size, align); | |
*pcap = cap + extend; | |
return data; | |
} | |
static Slice(i32) range(i32 n, Arena *a) | |
{ | |
Slice(i32) r = {}; | |
affirm(n < maxof(i32)); | |
for (i32 i = 0; i < n; i++) { | |
*push(a, &r) = i; | |
} | |
return r; | |
} | |
static Slice(Str) split(Str s, u8 delim, Arena *a) | |
{ | |
Slice(Str) r = {}; | |
iz beg = 0; | |
for (iz i = 0; i < s.len; i++) { | |
if (s.data[i] == delim) { | |
*push(a, &r) = slice(s, beg, i); | |
beg = i + 1; | |
} | |
} | |
*push(a, &r) = slice(s, beg, s.len); | |
return r; | |
} | |
static Slice(u8) append(Arena *a, Slice(u8) buf, Str s) | |
{ | |
while (buf.cap-buf.len < s.len) { | |
iz oldlen = buf.len; | |
buf.len = buf.cap; | |
push(a, &buf); | |
buf.len = oldlen; | |
} | |
memcpy(buf.data+buf.len, s.data, s.len); | |
buf.len += s.len; | |
return buf; | |
} | |
static Str join(Slice(Str) strings, Str delim, Arena *a) | |
{ | |
Slice(u8) buf = {}; | |
for (iz i = 0; i < strings.len; i++) { | |
if (i) buf = append(a, buf, delim); | |
buf = append(a, buf, strings.data[i]); | |
} | |
return (Str){buf.data, buf.len}; | |
} | |
static Slice(i64) generate_primes(i64 limit, Arena *a) | |
{ | |
Slice(i64) primes = {}; | |
if (limit > 2) { | |
*push(a, &primes) = 2; | |
} | |
for (i64 n = 3; n < limit; n += 2) { | |
b32 valid = true; | |
for (iz i = 0; valid && i<primes.len; i++) { | |
valid = n % primes.data[i]; | |
} | |
if (valid) { | |
*push(a, &primes) = n; | |
} | |
} | |
return primes; | |
} | |
// Demo | |
#include <stdio.h> | |
static void print(Str s) | |
{ | |
fwrite(s.data, 1, s.len, stdout); | |
putchar('\n'); | |
} | |
int main() | |
{ | |
static u8 mem[1<<21]; | |
Arena a = {mem, mem+lenof(mem)}; | |
Slice(i32) nums = range(10, &a); | |
for (iz i = 0; i < nums.len; i++) { | |
printf("%d%c", (int)nums.data[i], i==nums.len-1?'\n':' '); | |
} | |
Str input = S("foo bar baz"); | |
Slice(Str) words = split(input, ' ', &a); | |
print(input); | |
for (iz i = 0; i < words.len; i++) { | |
print(words.data[i]); | |
} | |
Str sentence = join(words, S(","), &a); | |
print(sentence); | |
Slice(i64) primes = generate_primes(100, &a); | |
printf("primes:"); | |
for (iz i = 0; i < primes.len; i++) { | |
printf(" %lld", (long long)primes.data[i]); | |
} | |
putchar('\n'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.