File: inner_union.rb

package info (click to toggle)
ruby-cstruct 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 412 kB
  • sloc: ruby: 1,008; makefile: 7
file content (26 lines) | stat: -rw-r--r-- 431 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# CStruct Examples
require 'cstruct'

# example:
# struct U in C\C++ (32-bit platform): 
# 
#struct U
#{
#    union NumericType
#    {
#        int   x;
#        int   y;  
#    };
#    NumericType value;
#};

# Named union is unsupported in CStruct. Fortunately, anonymous union can take the place of it.
# struct U in Ruby: 
class U < CStruct
  union:value do
    int32:x
    int32:y
  end
end

#  See also: 'anonymous_union.rb'