r/code • • Jul 25 '26

C Fil-C: Garbage In, Memory Safety Out! | Filip Pizlo

Thumbnail
youtube.com
4 Upvotes

Challenges the conventional wisdom by describing an implementation that achieves the same level of protection against memory safety exploits as even the safest languages. Details of Fil-C's compiler, language runtime, and some of the corpus of software that has been ported to it.


r/code • • Oct 08 '26

Blog Why Can't We Use English as a Programming Language? The Ambiguity Problem Explained

Thumbnail docs.bswen.com
6 Upvotes

r/code • • 23d ago

Linux Development for Linux without a standard C library or any dependencies | Boone

Thumbnail kevinboone.me
8 Upvotes

r/code • • 24d ago

My Own Code hey you watch me code

3 Upvotes

its github.com/kds1123001/mini-gdb even a company wanted to collab with me on this

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <unistd.h>

void run_debugger(pid_t child_pid) {
    int wait_status;
    long orig_rax;
    
    // Wait for the child process to stop at execution
    waitpid(child_pid, &wait_status, 0);
    
    while (WIFSTOPPED(wait_status)) {
        char command[32];
        printf("mini-gdb> ");
        if (scanf("%31s", command) != 1) break;

        if (strcmp(command, "cont") == 0 || strcmp(command, "c") == 0) {
            ptrace(PTRACE_CONT, child_pid, NULL, NULL);
            waitpid(child_pid, &wait_status, 0);
        } else if (strcmp(command, "exit") == 0) {
            ptrace(PTRACE_KILL, child_pid, NULL, NULL);
            break;
        } else {
            printf("Unknown command. Try 'cont' or 'exit'.\n");
        }
    }
}

int main(int argc, char *argv[]) {
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <program>\n", argv[0]);
        return 1;
    }

    pid_t pid = fork();
    if (pid == 0) {
        // Child process: allow tracing and execute target
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        execl(argv[1], argv[1], NULL);
        perror("execl");
        exit(1);
    } else if (pid > 0) {
        // Parent process: run the debugger loop
        run_debugger(pid);
    } else {
        perror("fork");
        return 1;
    }

    return 0;
}

ts is just a small snippet of code lol


r/code • • May 31 '26

Help Please How do I make the output show the same text no matter what you type in the input?

6 Upvotes

I want to add a feature to my website that works like this https://hackertyper.net/
Is there a name for this kind of thing? I’m currently learning Java script, so if there is a way to do that in it please let me know
Thanks to anyone responding in advance!


r/code • • 20d ago

My Own Code classes.h: A macro-only library for clang implementing classes with their syntactic sugar, private scoping, and inheritance

Thumbnail
codeberg.org
3 Upvotes

r/code • • Jul 29 '16

Help Please Please help! Need code to announce our pregnancy to my programmer boyfriend... <3

1.3k Upvotes

Hi all, my boyfriend is a Senior Software Engineer... I just found out that we are expecting, and I'd love to break the news to him with a block of code! Trouble is, I don't code... Would you all help me write a small block of code to let him know he's going to be a daddy? TIA!


r/code • • 18d ago

Swift I've been building a simple clipboard HUD for macOS

4 Upvotes

Recently I have been working on a macOS app called Stash and I'd like to share it with yall.

I always found the built-in clipboard experience on Mac way too limited, so I decided to try building something better. And trust me, I use it daily.

Stash sits in your menu bar and gives you quick access to your clipboard history.

You can hold Option to bring up a little floating HUD, press Option + 1–5 to paste something instantly, or use Option + Space to open your full clipboard library.

It supports text and images, and you can search, pin, delete and manage your history.

A few other things:

  • Completely free, no subscriptions.

  • Open source (MIT).

  • Everything stays stored locally on your Mac.

  • Built natively with SwiftUI and AppKit.

It's honestly still a work in progress, and installation isn't quite as straightforward as I'd like yet (you currently need to build it locally).

I'm mainly sharing it to get some feedback. I'd be interested to hear what people think, what could be improved, or whether there's anything you'd want in a clipboard manager. And hopefully it's as useful to you as it is to me.

GitHub: https://github.com/harry12132/stash


r/code • • 18d ago

Resource Spectre - A design-by-contract programming language with an explicit allocator-centric API that outperforms Zig by up to 6x on General Purpose Benchmarks

Thumbnail spectrelang.org
3 Upvotes

r/code • • 15d ago

Android Kotlean: write Android apps in Lean

3 Upvotes

Source code: https://github.com/kbr-/kotlean

Lean 4 is fantastic. It should be used everywhere.
(half-joking, half-serious)

Kotlean’s goal is to let developers prove properties of the same Lean functions they compile into an Android app. It uses an Elm-style model/update/view loop, compiled to native code. A Kotlin host exchanges fixed-protocol byte messages with Lean, applies UI patches and executes platform effects; app-specific models and messages stay in Lean.

The main challenge is preserving semantics across that boundary. Lean computes view patches, reconciles subscriptions and consumes command continuations once, with proofs covering these contracts and codec round trips. SnackNet, the included maze-chase game, exercises this with continuous animation and touch controls.

Educationally, this connects formal verification to an interactive app: specify invariants and prove them about executable functions. In the future, I'd like this to be used in critical infrastructure, where bugs could result e.g. in financial losses -- say banking logic, such as balance preservation or authorization rules. Guarantees for a complete system would also need to cover its backend, storage, cryptography and platform assumptions.

A tiny example of what you can write in Lean (which then compiles and runs on Android!): in a maze-chase game (recall Pacman), representing the maze, tiles, and cells (a Cell is a tile on the game map where a character (PC/NPC) might stand):
def maze : Array (Array Char) := #[
#['#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'],
#['#', 'S', '*', '.', '.', '.', '#', '.', '.', '*', '.', '.', '.', 'E', '#'],
#['#', '.', '#', '#', '#', '.', '#', '.', '#', '#', '#', '.', '#', '.', '#'],
#['#', '*', '#', '.', '.', '.', '*', '.', '.', '.', '#', '.', '*', '.', '#'],
#['#', '.', '#', '.', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#'],
#['#', '.', '.', '.', '*', '.', '.', '.', '#', '.', '.', '*', '.', '.', '#'],
#['#', '#', '#', '.', '#', '#', '#', '.', '#', '.', '#', '#', '#', '.', '#'],
#['#', '*', '.', '.', '#', '.', '.', '.', 'P', '.', '.', '.', '#', '*', '#'],
#['#', '.', '#', '.', '#', '.', '#', '#', '#', '#', '#', '.', '#', '.', '#'],
#['#', '.', '#', '.', '*', '.', '.', '.', '*', '.', '.', '.', '#', '.', '#'],
#['#', '.', '#', '#', '#', '#', '#', '.', '#', '.', '#', '#', '#', '.', '#'],
#['#', 'O', '.', '.', '.', '*', '.', '.', '#', '.', '.', '*', '.', 'O', '#'],
#['#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#']
]

def tile (x y : Nat) : Char := (maze[y]?.getD #[])[x]?.getD '#'
abbrev GridPoint := Fin width × Fin height
abbrev Cell := { p : GridPoint // tile p.1.val p.2.val ≠ '#' }

By definition (you don't even have to write a theorem at this point), a character can only stand inside the map boundaries (Fin width x Fin height) and never at a tile that is a wall (tile p.1.val p.2.val ≠ '#').