10

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;
Anirudha
  • 32,393
  • 7
  • 68
  • 89
Tyler Durden
  • 1,188
  • 2
  • 19
  • 35

1 Answers1

4

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);
}
Mark Heath
  • 48,273
  • 29
  • 137
  • 194