Skip to content

Instantly share code, notes, and snippets.

View imaami's full-sized avatar
🐺
C/C++/Linux ░▒▓▉▊▋▌▍▎▏

Juuso Alasuutari imaami

🐺
C/C++/Linux ░▒▓▉▊▋▌▍▎▏
  • Finland
View GitHub Profile
@imaami
imaami / sizeofplusplus.c
Created July 21, 2023 00:10
Cursed sizeof.
#include <stdio.h>
#define sizeof(x) (!(#x[0]^0x27)?:sizeof(x))
#define q(x) printf("%-7s\t%zu\n", #x, x)
#define p(x) q(sizeof(x))
int main (void)
{
char s[7], c;
@imaami
imaami / cartoon.c
Created July 20, 2023 21:09
A cartoonish C program.
#include <stdio.h>
#define ___ putchar
#define __ sizeof
#define _ __func__
int main(
void
){___(*(_+((*_>>(__(__(_))>>
4))&(*_>>__(_)))));___(*(_+((*_>>(__(__(_))>>
2))&(*_>>__(_)))));___(*(_+((*_>>(__(__(_))>>
1))&(*_>>__(_)))));___(*(_+((*_>>(__(__(_))>>
@imaami
imaami / spooky_message.c
Last active July 20, 2023 21:02
A spooky message in perfectly legible C.
/*----------------------------*
| s p o o k y m e s s a g e |
*----------------------------*/
#include <stdio.h>
#include <string.h>
__typeof__(~
sizeof("{%s, n%s}\n")) main
( __typeof__(~*
"")eof__,
__typeof__(*
@imaami
imaami / tautology.cpp
Created July 20, 2023 20:51
A value that is both bool(true) and EXIT_SUCCESS.
#include <cstdio>
int main() {
constexpr auto tautology{1ull << 63};
if (tautology)
std::puts("raw value evaluates to true");
if (static_cast<bool>(tautology))
std::puts("bool conversion equals true");
@imaami
imaami / includeinclude.sh
Created July 20, 2023 20:45
#include <#include> /* because why not? */
#!/usr/bin/bash
printf '%s\n' "int main(void) { puts(strchr(__FILE__, '#') ?: __FILE__); }" > './#include'
printf '#include <%s>\n' 'stdio.h' 'string.h' '#include' | cc -I. -o./includeinclude -xc -
./includeinclude
static const char *const SOURCE=(const char[]){
#embed __FILE__
,0}+72;
#include <stdio.h>
int main() {
puts(SOURCE);
}
@imaami
imaami / main.sh
Last active July 20, 2023 20:30
main? main.
#!/usr/bin/bash
#; / / #;
#; / / #;
#; / / #;
#;/ / #;
#; / #;
#; / ; ; ; ; #;
#; / ####### #;
#;/ ## C ## #;
#; ;#####; #;
@imaami
imaami / dstr_fini_test.c
Created July 9, 2023 21:43
Testing optimization levels
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define stringify_(x) #x
#define stringify(x) stringify_(x)
@imaami
imaami / dstr_view_demo.c
Last active July 9, 2023 00:58
An SSO thing in C, WIP
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define stringify_(x) #x
#define stringify(x) stringify_(x)
@imaami
imaami / terror.c
Created July 1, 2023 11:38
strerror() but more cursed
#include <pthread.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
static void *fn (void *p)
{
pthread_detach(pthread_self());