Skip to content

Instantly share code, notes, and snippets.

@rtldg
Last active March 4, 2025 13:27
Show Gist options
  • Select an option

  • Save rtldg/a5612aa142e65bddddf454acae0ae7a6 to your computer and use it in GitHub Desktop.

Select an option

Save rtldg/a5612aa142e65bddddf454acae0ae7a6 to your computer and use it in GitHub Desktop.
using this in godbolt to check stuff for metamod:source
#include <stdio.h>
#ifdef _MSC_VER
#define PACKED
#pragma pack(push, 1)
#else
#define PACKED __attribute__((packed))
#endif
typedef struct PACKED thing {
thing() : a(10), b(15) { printf("hello %d %d\n", a, b); }
thing& operator=(thing& other) { this->a = other.a; this->b = other.b; }
~thing() { puts("bye"); }
int a;
short b;
} thing;
#ifdef _MSC_VER
#pragma pack(pop)
#endif
thing getthing(int a, int b) {
//static_assert(sizeof(thing) == 5, "fuck!");
thing t;
t.a = a;
t.b = b;
//t.c = 5;
//t.d = 7;
//for (int i = 0; i < sizeof(t.b); i++) t.b[i] = b;
return t;
}
void waaa() {
auto t = getthing(1,2);
printf("%d %d", t.a, t.b);
}
#include <stdio.h>
class Test {
public:
Test() : Z(100) {}
float Add(
int a, int b,
float c, float d, float e, float f,
int g, int p, int q,
float h, float i, float j, float k,
int l, int m, float r, int n,
float o, float s
) {
return Z + a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s;
}
int Z;
};
void waaa() {
Test t;
float res = t.Add(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
printf("%f\n", res);
}
#[repr(C)]
pub struct Vectorf3 {
pub a: f32,
pub b: f32,
pub c: f32,
}
#[no_mangle]
pub extern "C" fn get_vectorf3(a: i32, b: i32) -> Vectorf3 {
Vectorf3 { a: a as f32, b: b as f32, c: 3.0 }
}
#[no_mangle]
pub extern "C" fn use_vectorf3(v: Vectorf3) -> f32 {
v.a + v.b + v.c
}
#[no_mangle]
pub extern "C" fn thing() {
let v = get_vectorf3(1,2);
let sum = v.a + v.b + v.c;
//println!("{}", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment