我正在将一些 C++ 转换为 C# 代码,我看到了以下定义:
#define x 'liaM'
首先,这个单引号常量是什么意思?我是否在 c# 中将其设为字符串常量?
其次,这个常量被赋值给 C++ 中的一个 uint 变量。这是如何运作的?
uint m = x;
这有时称为FOURCC。有一个 Windows API 可以将字符串转换为名为mmioStringToFOURCC的 FOURCC ,这里有一些 C# 代码可以做同样的事情:
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);
}