Skip to content

Instantly share code, notes, and snippets.

View zxubian's full-sized avatar
🦊

Andrey Kirpach zxubian

🦊
View GitHub Profile
@zxubian
zxubian / byte_swap_all_members.zig
Last active September 19, 2022 07:59
Function to byte-swap all members of a struct in zig using reflection
const assert = std.debug.assert;
// uses reflection to byte-swap all members of a packed struct
// layout is preserved
fn byte_swap_all_members(comptime T: type, struct_pointer: *T) void {
comptime assert(@typeInfo(T).Struct.layout != .Auto);
comptime assert(@mod(@bitSizeOf(T), 8) == 0);
var raw_bytes = @ptrCast([*]u8, std.mem.asBytes(struct_pointer));
comptime var start_index: u32 = 0;
inline for (std.meta.fields(T)) |field| {
@zxubian
zxubian / clion-makefile-setup.md
Last active August 16, 2023 03:34
Running & Building a C Makefile Project with CLion & WSL (January 2022)

Running & Building a C Makefile Project with CLion & WSL (January 2022)

  • Set CLion Toolchain to WSL
    • Settings/Build, Execution & Deployment/Toolchains
    • Make sure all checks pass
    • If necessary, install C build tools on WSL side sudo apt-get install build-essential
  • From CLion, use File/Open... -> your MakeFile -> "Open as Project" -Note: if your MakeFile does not contain an "all" target, the CLion Makefile plugin thing might get angry and not parse any of the other targets
  • Go to "Edit Configurations" (on the upper-right)
// BluetoothLowEnergy.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#pragma warning (disable: 4068)
#include <windows.h>
#include <stdio.h>
#include <tchar.h>