April 2020
Intermediate to advanced
412 pages
9h 58m
English
We will create a simple program that can detect the endianness of the target platform. Follow these steps to do so:
#include <iostream>int main() { union { uint32_t i; uint8_t c[4]; } data; data.i = 0x01020304; if (data.c[0] == 0x01) { std::cout << "Big-endian" << std::endl; } else { std::cout << "Little-endian" << std::endl; }}
cmake_minimum_required(VERSION 3.5.1)project(endianness)add_executable(endianness ...
Read now
Unlock full access