cunion.pyx 532 Bytes
Newer Older
1
__doc__ = u"""
Stefan Behnel's avatar
Stefan Behnel committed
2 3 4 5 6
    >>> test_i()
    >>> test_c()
    >>> test_p()
"""

7 8 9 10 11 12 13
cdef union Spam:
    int i
    char c
    float *p[42]

cdef Spam spam, ham

Stefan Behnel's avatar
Stefan Behnel committed
14
cdef void eggs_i(Spam s):
15 16 17 18
    cdef int j
    j = s.i
    s.i = j

Stefan Behnel's avatar
Stefan Behnel committed
19 20 21 22 23 24 25 26 27 28
cdef void eggs_c(Spam s):
    cdef char c
    c = s.c
    s.c = c

cdef void eggs_p(Spam s):
    cdef float *p
    p = s.p[0]
    s.p[0] = p

29
spam = ham
Stefan Behnel's avatar
Stefan Behnel committed
30 31 32 33 34 35 36 37 38 39 40 41 42

def test_i():
    spam.i = 1
    eggs_i(spam)

def test_c():
    spam.c = c'a'
    eggs_c(spam)

def test_p():
    cdef float f
    spam.p[0] = &f
    eggs_p(spam)