Skip to content

Instantly share code, notes, and snippets.

@yoggy
yoggy / CreateProcess_CreateNoWindow_Test.cpp
Created March 6, 2012 09:36
How to use CreateProcess() function (WIN32)
//
// see also...
//
// CreateProcess (MSDN)
// http://msdn.microsoft.com/ja-jp/library/cc429066.aspx
//
#include <SDKDDKVer.h>
#include <windows.h>
int APIENTRY WinMain(HINSTANCE hInstance,
@lynxluna
lynxluna / main.c
Created December 8, 2012 22:01
Win32 Game Loop
#include <Windows.h>
#include <tchar.h>
#define CURRENT_WND_CLASS _T("GameWndClass_Didiet")
#define DEF_CX 800
#define DEF_CY 600
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
INT WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
@aras-p
aras-p / preprocessor_fun.h
Last active May 3, 2025 13:47
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@philipheimboeck
philipheimboeck / Readme.md
Last active March 29, 2023 13:20
C++ String: An own String implementation with operator overloading and free methods

C++ String

Example application that demonstrates the use of the following:

  • Operator overloading
    • Free Operators
    • Class Operators
  • Friendship
  • Iterator
@mmmunk
mmmunk / freestanding_hello.c
Created September 26, 2016 09:30
Freestanding MinGW
// Freestanding with MinGW:
// http://nullprogram.com/blog/2016/01/31/
// http://nullprogram.com/blog/2016/02/28/
// https://support.microsoft.com/da-dk/kb/99456
#include <windows.h>
int WINAPI mainCRTStartup(void)
{
char msg[] = "Hello, world!\n";
@nickrolfe
nickrolfe / windows_modern_opengl_context.c
Last active April 21, 2025 16:43
Sample code showing how to create a window using a modern OpenGL core profile context without any libraries other than the standard Win32 wglXXX calls.
// Sample code showing how to create a modern OpenGL window and rendering context on Win32.
#include <windows.h>
#include <gl/gl.h>
#include <stdbool.h>
typedef HGLRC WINAPI wglCreateContextAttribsARB_type(HDC hdc, HGLRC hShareContext,
const int *attribList);
wglCreateContextAttribsARB_type *wglCreateContextAttribsARB;
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active April 26, 2025 00:19
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@tommai78101
tommai78101 / unicode.c
Last active February 20, 2025 11:42
UTF-8 to UTF-16 one-way conversion, written in C
#include <stdio.h>
#include <stdlib.h>
#include <uchar.h>
#include <locale.h>
#define __STD_UTF_16__
//Pointer arrays must always include the array size, because pointers do not know about the size of the supposed array size.
void utf8_to_utf16(unsigned char* const utf8_str, int utf8_str_size, char16_t* utf16_str_output, int utf16_str_output_size) {
//First, grab the first byte of the UTF-8 string
@ChlorUpload
ChlorUpload / main.cpp
Last active October 8, 2024 18:17
A Game loop using PeekMessage function
// Set project as empty windows project.
// A game loop using PeekMessage function.
// Uses double buffering.
#include <Windows.h>
#include <time.h>
#include <math.h>
#pragma comment(lib, "winmm.lib")
@FadeMind
FadeMind / fuck_telemetry.cmd
Created August 26, 2020 13:24
Turn Off Telemetry in Windows 10
@echo off
echo.
openfiles > NUL 2>&1
if %errorlevel% NEQ 0 (
echo You are not running as Administrator...
echo This batch cannot do it's job without elevation!
echo.
echo Right-click and select ^'Run as Administrator^' and try again...
echo.