-
-
Save wchargin/2e3ac6f9cbc775578351ce77b05010bf to your computer and use it in GitHub Desktop.
cursed code to get the sequence "!||" to be valid
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
#!/bin/sh | |
rustc +nightly --crate-type=staticlib forty_two.rs || exit 1 | |
gcc main.c -L. -lforty_two || exit 1 | |
./a.out | |
# prints: forty_two() = 42 |
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
#![no_std] | |
#![no_core] | |
#![feature(no_core, lang_items, auto_traits)] | |
#[no_mangle] | |
pub extern "C" fn forty_two() -> u32 { | |
!|| () // evaluates to 42 | |
} | |
#[lang = "not"] | |
pub trait Not { | |
type Output; | |
fn not(self) -> Self::Output; | |
} | |
impl<T> Not for T { | |
type Output = u32; | |
fn not(self) -> u32 { | |
42 | |
} | |
} | |
// mandatory lang items since we don't have ::core | |
#[lang = "sized"] | |
pub trait Sized {} | |
#[lang = "copy"] | |
pub unsafe trait Copy {} | |
#[lang = "freeze"] | |
unsafe auto trait Freeze {} | |
#[lang = "drop_in_place"] | |
pub unsafe fn drop_in_place<T: ?Sized>(_: *mut T) { | |
loop {} | |
} |
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
#include <stdint.h> | |
#include <stdio.h> | |
extern uint32_t forty_two(); | |
int main() { | |
printf("forty_two() = %d\n", forty_two()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment