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
  • 31,626
  • 7
  • 66
  • 85
Tyler Durden
  • 1,118
  • 1
  • 18
  • 34

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
  • 46,816
  • 28
  • 132
  • 191