Let talk about using reinterpret_cast and binary files (C++)

CuriousTommy

Well-Known Member
OP
Member
Joined
Jul 22, 2014
Messages
524
Trophies
0
Age
27
XP
647
Country
United States
Hello Everyone,

Recently I have been discovering the magic wonders of the reinterpret_cast function. I have been trying to find a solution for reading and writing any binary file in memory (something like fstream, but for binary files in memory). For example, I want to read from a binary file in a dynamic char array). It seems like reinterpret_cast solves this problem.

I made a very basic program to see if I was able to have data in a char array be accessed by an int pointer. It felt really satisfying being able to put an ASCII value in the pointer int and have the change be shown in a char array.

With all that being said, I have also heard that using reinterpret_cast is very dangerous. Is it dumb to use reinterpret_cast for in-memory binary file manipulation, or is it normal to use reinterpret_cast this way? I heard it is used for bit manipulation, but I am not sure if that also applies to reading and writing to binary files in memory.

I was thinking of doing a char binary reader and writer for the summer as a fun project, but I don't want to develop any bad coding habit that would be considered reckless or extremely dangerous. I will implement this as a class, so there will be error checking to reduce misuse or improper access.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: This movie rip so werid has 10180p quality but the audios ripped with movie theater audio quality