c_eval(expr)
Evaluate a C arithmetic/logic expression and return the result
Examples:
>>> c_eval('10 + (5 / 3)')
11
>>> c_eval('!0')
1
>>> c_eval('sizeof(x)')
128
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr |
str
|
C expression |
required |
Returns:
Name | Type | Description |
---|---|---|
result |
Union[int, float]
|
the expression evaluation result |
Raises:
Type | Description |
---|---|
EvalError
|
expression evaluation error |
Source code in cstruct/c_expr.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
eval_compare(node)
Evaluate a compare node
Source code in cstruct/c_expr.py
88 89 90 91 92 93 94 95 96 |
|
eval_div(node)
Evaluate div node (integer/float)
Source code in cstruct/c_expr.py
99 100 101 102 103 104 105 106 |
|
eval_get(node)
Get definition/struct by name
Source code in cstruct/c_expr.py
80 81 82 83 84 85 |
|