From 23c768e505fbcdb7776e1f20e212d47442614f34 Mon Sep 17 00:00:00 2001 From: bixb922 <70152274+bixb922@users.noreply.github.com> Date: Sat, 4 May 2024 09:33:14 -0400 Subject: [PATCH] Document that the Viper bool() cast is a bit different from C (bool) cast --- Improving-performance-with-Viper-code.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Improving-performance-with-Viper-code.md b/Improving-performance-with-Viper-code.md index 24c8883..bf7d0be 100644 --- a/Improving-performance-with-Viper-code.md +++ b/Improving-performance-with-Viper-code.md @@ -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.