I was translating some C++ to C# code and I saw the below definiton:
#define x 'liaM'
First, what does this single quoted constant mean? Do I make it a string constant in c#?
Second, this constant is assigned as value to a uint variable in C++. How does that work?
uint m = x;
This is sometimes called a FOURCC. There's a Windows API that can convert from a string into a FOURCC called mmioStringToFOURCC and here's some C# code to do the same thing:
public static int ChunkIdentifierToInt32(string s)
{
if (s.Length != 4) throw new ArgumentException("Must be a four character string");
var bytes = Encoding.UTF8.GetBytes(s);
if (bytes.Length != 4) throw new ArgumentException("Must encode to exactly four bytes");
return BitConverter.ToInt32(bytes, 0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With