Skip to content

Instantly share code, notes, and snippets.

@ksyx
ksyx / README.md
Created December 10, 2021 20:14
A toy that stores some global variables by writing the binary itself

Global Variable Storage

Background

VBA could store some data by simply putting those data into Excel cells or Powerpoint TextBoxes, which is kinda counterintuitive for a programming language to have persist value storage even after stopped running, though perfectly reasonable. Could we do similar thing in the magical C++? This heavily platform dependent toy (ELF + POSIX) achieves this.

Working principle

It simply utilizes the .data segment by either specifying some variables to be put there, or just utilize the fact that initialized values are put there. Some magical operations used:

  • The variables __data_start and edata provided by linker scripts
  • Read output of awk with popen

License

MIT License

@ksyx
ksyx / foo.cpp
Last active August 22, 2021 13:54
Argument passing utility with unified outside interface available
/*
A utility choosing version to call and carry extra information to the call
by argument with a unified outside interface. Call global functions foo, bar, foobar with
just one interface f.foo(int, int, void*, int, int), with arguments after void* directly
fed into what the function void* points to. Change bool types in whole code to add other information to pass.
Type conversions inside structure not so tidy yet.
Copyright (c) ksyx 2021. MIT Licensed.
*/
@ksyx
ksyx / CImgConfig.cmake.in
Last active April 20, 2021 12:41
CMakeify CImg
set(CImg_VERSION 0.0.0)
@PACKAGE_INIT@
set_and_check(CIMG_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
check_required_components(CImg)

Keybase proof

I hereby claim:

  • I am ksyx on github.
  • I am ksyx (https://keybase.io/ksyx) on keybase.
  • I have a public key ASA0w9fST3Nr_Ska3j6YA0yCdldIGH4HniiAdEBrWcYOCQo

To claim this, I am signing this object: