#define UNION_CAST(x, destType) \
(((union {__typeof__(x) a; destType b;})x).b)
You can then use
int myInt = UNION_CAST(myFloat, int);
// Did you know that [Compiler Explorer](godbolt.org) allows you to include any file | |
// from the internet ? | |
// | |
// Just add the following line to your C source: | |
// | |
// #include <https://gist.githubusercontent.com/g-berthiaume/84160d113e5639e480eae9a0ef3af1ba/raw/1fde54c83ec3ff74dad536e0bb36d14d4db4e36b/godbolt_utils.h> | |
// | |
// This file's purpose is to create a collection of utilities for increasing my productivity on godbolt. | |
// This file is unlicensed. Do what you want with it. :^) | |
// g-berthiaume - 2024 |
// run it online: | |
// https://repl.it/repls/SquigglyPessimisticCron | |
// gberthiaume 2020 | |
// | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdint.h> | |
char* fizzbuzz(uint8_t const n) | |
{ |
#!/usr/bin/env python3 | |
# -*- coding=utf-8 -*- | |
""" | |
Python snippets: How to insert lines in a file. | |
NOTES: | |
Only standard python 3 library needed. | |
Tested on python 3.7 on Windows10. | |
G.Berthiaume 2019 | |
""" |
// Count the consecutive zero bits (trailing) on the right with multiply and lookup | |
// From https://graphics.stanford.edu/~seander/bithacks.html | |
unsigned int v; // find the number of trailing zeros in 32-bit v | |
int r; // result goes here | |
static const int MultiplyDeBruijnBitPosition[32] = { | |
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, | |
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 | |
}; | |
r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27]; |
#!/usr/bin/env python3 | |
# -*- coding=utf-8 -*- | |
""" | |
Code snippet for asking user a yes/no question. | |
No dependencies needed. | |
Tested with Python 3.7 | |
G.Berthiaume 2019 | |
""" | |
from tkinter import messagebox |
# ------------------------------------------------------------------------------- | |
# list_programs.ps1 | |
# Will list all installed programs in Windows 10 using the terminal. | |
# From https://www.itechtics.com/list-installed-programs-windows-10/ | |
# | |
# G. Berthiaume | |
# 2018 | |
# ------------------------------------------------------------------------------- | |
Write-Output "Date: $(Get-Date -Format u)" |
#!/usr/bin/env python3 | |
# -*- coding=utf-8 -*- | |
""" | |
Display weather forecast from the wttr website in terminal. | |
Dependency: | |
requests | |
Tested with Python 3.7 on windows 10. | |
G.Berthiaume 2018 |
::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:: ListPrograms.bat | |
::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:: Will list all installed programs. | |
:: | |
:: G. Berthiaume | |
:: 2018 | |
::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
@echo off | |
echo List all programs installed on %date%, %time% |