Document that the Viper bool() cast is a bit different from C (bool) cast

bixb922
2024-05-04 09:33:14 -04:00
parent 03966b45c2
commit 23c768e505

@@ -94,7 +94,7 @@ In case you are familiar with C: The viper data types are similar to some C lang
|----------------|----------------------|------|
|`int` |`long int` | 32 bit signed integer|
|`uint` | `unsigned long int`| 32 bit unsigned integer |
|`bool` | `long int`| 32 bit signed integer, but only 0 (False) and not zero (True) is used |
|`bool` | `long int`| 32 bit signed integer, where 0 is False and not zero is True. This is unlike C bool where 0 is false and 1 is true |
|`ptr32` | `*long int` | memory pointer to a 32 bit signed integer |
|`ptr16` |`*unsigned short int` |memory pointer to a 16 bit unsigned integer |
|`ptr8` | `*unsigned char`|memory pointer to an 8 bit unsigned integer |
@@ -281,6 +281,7 @@ def test_uint_int_assignments():
```
## The viper bool data type
A bool viper variable can be True or False. Boolean expressions are evaluated using the viper bool data type. This makes logic computations fast.
You create a bool viper variable by assigning `True`, `False` or the result of a logical expression of constants and viper bool variables that yields `True` or `False`, for example:
@@ -310,7 +311,7 @@ def cast_bools():
y = int(b)
# Now y holds the same value as x
```
Similar to `int()` and `uint()`, `bool()` is a cast operator. If used on a viper variable, only the type is changed, no conversion takes place (similar to casting in C language).
The explanation of this behavior is that similar to `int()` and `uint()`, `bool()` is a cast operator. If used on a viper variable, only the type is changed, no conversion takes place (this is unlike the C (bool) cast, where the integer is converted to 0 or 1).
## The viper ptr32, ptr16 and ptr8 data types
These data types are pointers to memory, similar to a C language `long *p;` or `unsigned char *p`. This is rather unusual for Python, where no pointers exist and memory access is well hidden within objects that protect that access.