code_junkie

C++ union in C#

Nov 11th, 2011
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. struct Foo {
  2. float bar;
  3.  
  4. union {
  5. int killroy;
  6. float fubar;
  7. } as;
  8. }
  9.  
  10. [StructLayout(LayoutKind.Explicit)]
  11. public struct SampleUnion
  12. {
  13. [FieldOffset(0)] public float bar;
  14. [FieldOffset(4)] public int killroy;
  15. [FieldOffset(4)] public float fubar;
  16. }
  17.  
  18. public struct Foo
  19. {
  20. float bar;
  21. int Kilroy;
  22. float Fubar;
  23. }
  24.  
  25. struct LibrarySType {
  26. AnotherType *anotherTypeBuff;
  27. int oneSetOfFlags;
  28. int anotherSetOfFlags;
  29. union {
  30. struct {
  31. int structMember1;
  32. ...
  33. } oneUseOfThisLibraryType;
  34. struct {
  35. char *structMember2;
  36. ...
  37. } anotherUseOfThisLibraryType;
  38. ...
  39. } u;
  40. int64 *moreStuff;
  41. ... you get the idea
Add Comment
Please, Sign In to add comment