From 1415d48bbbff9bb4146288e1b7a633aca96c1b9a Mon Sep 17 00:00:00 2001 From: Tbusk Date: Wed, 12 Nov 2025 17:33:21 -0500 Subject: [PATCH 1/5] change: improve and expand the data types section in the main tutorial --- .../main/02-00-basics/02-04-data-types.md | 115 +++++++++++++++--- 1 file changed, 96 insertions(+), 19 deletions(-) diff --git a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md index 109217df..70d34c67 100644 --- a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md +++ b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md @@ -13,22 +13,94 @@ convention for constants is `ALL_UPPER_CASE`. Vala supports a set of the simple types as most other languages do. -- Byte, `char`, `uchar`; their names are *char* for historical - reasons. -- Character, `unichar`; a 32-bit Unicode character -- Integer, `int`, `uint` -- Long Integer, `long`, `ulong` -- Short Integer, `short`, `ushort` -- Guaranteed-size Integer, `int8`, `int16`, `int32`, `int64` as well - as their unsigned siblings `uint8`, `uint16`, `uint32`, `uint64`. - The numbers indicate the lengths in bits. -- Float number, `float`, `double` -- Boolean, `bool`; possible values are `true` and `false` -- Compound, `struct` -- Enumeration, `enum`; represented by integer values, not as classes - like Java's enums - -Here are some examples. +### 2.4.1.1 Byte + +| Type | Size | Range | +|---------|--------|-------------| +| `char` | 1 byte | -128 to 127 | +| `uchar` | 1 byte | 0 to 255 | + +These have the name `char` in them for historical reasons. + +### 2.4.1.2 Integers + +| Type | Size | Range | +|--------|---------|---------------------------------| +| `int` | 4 bytes | -2,147,483,648 to 2,147,483,647 | +| `uint` | 4 bytes | 0 to 4,294,967,295 | + +### 2.4.1.3 Long + +| Type | Size | Range | +|---------|---------|---------------------------------| +| `long` | 4 bytes | -2,147,483,648 to 2,147,483,647 | +| `ulong` | 4 bytes | 0 to 4,294,967,295 | + +### 2.4.1.4 Short + +| Type | Size | Range | +|----------|---------|-------------------| +| `short` | 2 bytes | -32,768 to 32,767 | +| `ushort` | 2 bytes | 0 to 65,535 | + +### 2.4.1.5 Guaranteed-size Signed Integers + +| Type | Size | Range | +|---------|---------|---------------------------------------------------------| +| `int8` | 1 byte | -128 to 127 | +| `int16` | 2 bytes | -32,768 to 32,767 | +| `int32` | 4 bytes | -2,147,483,648 to 2,147,483,647 | +| `int64` | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | + +### 2.4.1.6 Guaranteed-size Unsigned Integers + +| Type | Size | Range | +|----------|---------|---------------------------------| +| `uint8` | 1 byte | 0 to 255 | +| `uint16` | 2 bytes | 0 to 65,535 | +| `uint32` | 4 bytes | 0 to 4,294,967,295 | +| `uint64` | 8 bytes | 0 to 18,446,744,073,709,551,615 | + +### 2.4.1.7 Floating Points + +| Type | Size | Range | Precision | +|----------|---------|------------------------|------------| +| `float` | 4 bytes | 1.18e-38 to 3.4e+38 | ~7 digits | +| `double` | 8 bytes | 2.23e-308 to 1.80e+308 | ~16 digits | + +Based on the IEEE 754-1985 standard. + +### 2.4.1.8 Array Indexing / Loop Counting + +| Type | Size | Range | +|-----------|--------------|---------------------------------------------------------| +| `size_t` | 2 to 8 bytes | 0 to 18,446,744,073,709,551,615 | +| `ssize_t` | 2 to 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | + +Typically, these are compiler and architecture dependent. + +For more information, please refer to [size_t](https://en.cppreference.com/w/c/types/size_t.html) on the C++ reference. + +### 2.4.1.9 Booleans + +| Type | Size | Values | +|--------|--------|---------------| +| `bool` | 1 byte | true or false | + +### 2.4.1.10 Unicode Characters + +| Type | Size | Standard | +|------------|--------------|----------| +| `unichar` | 4 bytes | UTF-32 | +| `unichar2` | 1 to 2 bytes | UTF-16 | + +### 2.4.1.1 Compound +- `struct` + +### 2.4.1.12 Enumeration +- `enum` : values are integers, unlike Java's enums + +### Examples ```vala unichar c = 'u'; @@ -63,8 +135,13 @@ with *.MIN* and *.MAX*, e.g. `int.MIN` and `int.MAX`. ## 2.4.2. Strings -The data type for strings is `string`. Vala strings are UTF-8 encoded -and immutable. +| Type | Size per Character | Max Length (theoretical) | +|---------------------|--------------------|------------------------------| +| `string` (UTF-8) | 1 byte | 0 - 2,147,483,647 characters | +| `string16` (UTF-16) | 1 to 2 bytes | 0 - 2,147,483,647 characters | +| `string32` (UTF-32) | 4 bytes | 0 - 2,147,483,647 characters | + +Strings in Vala are immutable. ```vala string text = "A string literal"; @@ -385,7 +462,7 @@ Here are some examples: var a = 123; // int var b = 123u; // uint var c = 123l; // long -var d = 123ll; // ulong +var d = 123ll; // int64 var e = 123ul; // ulong var f = 123ull; // uint64 ``` From 68dc3a58cbea7e0eceb5c68b2ba40f0efb607b49 Mon Sep 17 00:00:00 2001 From: Tbusk Date: Wed, 12 Nov 2025 17:44:38 -0500 Subject: [PATCH 2/5] patch: fix typo in header in compound data type section --- .../programming-language/main/02-00-basics/02-04-data-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md index 70d34c67..2576f895 100644 --- a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md +++ b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md @@ -94,7 +94,7 @@ For more information, please refer to [size_t](https://en.cppreference.com/w/c/t | `unichar` | 4 bytes | UTF-32 | | `unichar2` | 1 to 2 bytes | UTF-16 | -### 2.4.1.1 Compound +### 2.4.1.11 Compound - `struct` ### 2.4.1.12 Enumeration From b425917903163b822d1930a40cdc43611f9819ee Mon Sep 17 00:00:00 2001 From: Tbusk Date: Wed, 12 Nov 2025 18:46:04 -0500 Subject: [PATCH 3/5] patch: adjust ranges to show just the guaranteed amount and added a disclaimer to the top. --- .../main/02-00-basics/02-04-data-types.md | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md index 2576f895..d72f3c66 100644 --- a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md +++ b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md @@ -11,14 +11,17 @@ convention for constants is `ALL_UPPER_CASE`. ## 2.4.1. Value Types -Vala supports a set of the simple types as most other languages do. +Vala supports a set of the simple types as most other languages do. + +The following ranges may differ based on a variety of factors, such as +the platform, the compiler, the CPU architecture, etc. ### 2.4.1.1 Byte -| Type | Size | Range | -|---------|--------|-------------| -| `char` | 1 byte | -128 to 127 | -| `uchar` | 1 byte | 0 to 255 | +| Type | Size | Range | +|---------|--------|----------------------| +| `char` | 1 byte | at least -127 to 127 | +| `uchar` | 1 byte | 0 to at least 255 | These have the name `char` in them for historical reasons. @@ -26,40 +29,40 @@ These have the name `char` in them for historical reasons. | Type | Size | Range | |--------|---------|---------------------------------| -| `int` | 4 bytes | -2,147,483,648 to 2,147,483,647 | -| `uint` | 4 bytes | 0 to 4,294,967,295 | +| `int` | 4 bytes | -2,147,483,647 to 2,147,483,647 | +| `uint` | 4 bytes | 0 to at least 4,294,967,295 | ### 2.4.1.3 Long -| Type | Size | Range | -|---------|---------|---------------------------------| -| `long` | 4 bytes | -2,147,483,648 to 2,147,483,647 | -| `ulong` | 4 bytes | 0 to 4,294,967,295 | +| Type | Size | Range | +|---------|---------|------------------------------------------| +| `long` | 4 bytes | at least -2,147,483,647 to 2,147,483,647 | +| `ulong` | 4 bytes | 0 to at least 4,294,967,295 | ### 2.4.1.4 Short -| Type | Size | Range | -|----------|---------|-------------------| -| `short` | 2 bytes | -32,768 to 32,767 | -| `ushort` | 2 bytes | 0 to 65,535 | +| Type | Size | Range | +|----------|---------|----------------------------| +| `short` | 2 bytes | at least -32,767 to 32,767 | +| `ushort` | 2 bytes | 0 to at least 65,535 | ### 2.4.1.5 Guaranteed-size Signed Integers -| Type | Size | Range | -|---------|---------|---------------------------------------------------------| -| `int8` | 1 byte | -128 to 127 | -| `int16` | 2 bytes | -32,768 to 32,767 | -| `int32` | 4 bytes | -2,147,483,648 to 2,147,483,647 | -| `int64` | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | +| Type | Size | Range | +|---------|---------|------------------------------------------------------------------| +| `int8` | 1 byte | at least -127 to 127 | +| `int16` | 2 bytes | at least -32,767 to 32,767 | +| `int32` | 4 bytes | at least -2,147,483,647 to 2,147,483,647 | +| `int64` | 8 bytes | at least -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 | ### 2.4.1.6 Guaranteed-size Unsigned Integers -| Type | Size | Range | -|----------|---------|---------------------------------| -| `uint8` | 1 byte | 0 to 255 | -| `uint16` | 2 bytes | 0 to 65,535 | -| `uint32` | 4 bytes | 0 to 4,294,967,295 | -| `uint64` | 8 bytes | 0 to 18,446,744,073,709,551,615 | +| Type | Size | Range | +|----------|---------|------------------------------------------| +| `uint8` | 1 byte | 0 to at least 255 | +| `uint16` | 2 bytes | 0 to at least 65,535 | +| `uint32` | 4 bytes | 0 to at least 4,294,967,295 | +| `uint64` | 8 bytes | 0 to at least 18,446,744,073,709,551,615 | ### 2.4.1.7 Floating Points @@ -72,12 +75,10 @@ Based on the IEEE 754-1985 standard. ### 2.4.1.8 Array Indexing / Loop Counting -| Type | Size | Range | -|-----------|--------------|---------------------------------------------------------| -| `size_t` | 2 to 8 bytes | 0 to 18,446,744,073,709,551,615 | -| `ssize_t` | 2 to 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | - -Typically, these are compiler and architecture dependent. +| Type | Size | Range | +|-----------|--------------|------------------------------------------------------------------| +| `size_t` | 2 to 8 bytes | 0 to at least 18,446,744,073,709,551,615 | +| `ssize_t` | 2 to 8 bytes | at least -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 | For more information, please refer to [size_t](https://en.cppreference.com/w/c/types/size_t.html) on the C++ reference. From da8b13e58129fb35444a20eaa45c01f69d8685d2 Mon Sep 17 00:00:00 2001 From: Tbusk Date: Wed, 12 Nov 2025 18:47:29 -0500 Subject: [PATCH 4/5] patch: add range to missed section --- .../main/02-00-basics/02-04-data-types.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md index d72f3c66..c641a651 100644 --- a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md +++ b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md @@ -27,10 +27,10 @@ These have the name `char` in them for historical reasons. ### 2.4.1.2 Integers -| Type | Size | Range | -|--------|---------|---------------------------------| -| `int` | 4 bytes | -2,147,483,647 to 2,147,483,647 | -| `uint` | 4 bytes | 0 to at least 4,294,967,295 | +| Type | Size | Range | +|--------|---------|------------------------------------------| +| `int` | 4 bytes | at least -2,147,483,647 to 2,147,483,647 | +| `uint` | 4 bytes | 0 to at least 4,294,967,295 | ### 2.4.1.3 Long From 64ce9115673c4d7e656d1737c9ec17898b3c6124 Mon Sep 17 00:00:00 2001 From: Tbusk Date: Thu, 13 Nov 2025 12:53:28 -0500 Subject: [PATCH 5/5] patch: adding pluses to data type byte size to signify minimum and expansibility --- .../main/02-00-basics/02-04-data-types.md | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md index c641a651..899f8fd0 100644 --- a/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md +++ b/docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md @@ -18,51 +18,51 @@ the platform, the compiler, the CPU architecture, etc. ### 2.4.1.1 Byte -| Type | Size | Range | -|---------|--------|----------------------| -| `char` | 1 byte | at least -127 to 127 | -| `uchar` | 1 byte | 0 to at least 255 | +| Type | Size | Range | +|---------|----------|----------------------| +| `char` | 1+ bytes | at least -127 to 127 | +| `uchar` | 1+ bytes | 0 to at least 255 | These have the name `char` in them for historical reasons. ### 2.4.1.2 Integers -| Type | Size | Range | -|--------|---------|------------------------------------------| -| `int` | 4 bytes | at least -2,147,483,647 to 2,147,483,647 | -| `uint` | 4 bytes | 0 to at least 4,294,967,295 | +| Type | Size | Range | +|--------|----------|------------------------------------------| +| `int` | 4+ bytes | at least -2,147,483,647 to 2,147,483,647 | +| `uint` | 4+ bytes | 0 to at least 4,294,967,295 | ### 2.4.1.3 Long -| Type | Size | Range | -|---------|---------|------------------------------------------| -| `long` | 4 bytes | at least -2,147,483,647 to 2,147,483,647 | -| `ulong` | 4 bytes | 0 to at least 4,294,967,295 | +| Type | Size | Range | +|---------|----------|------------------------------------------| +| `long` | 4+ bytes | at least -2,147,483,647 to 2,147,483,647 | +| `ulong` | 4+ bytes | 0 to at least 4,294,967,295 | ### 2.4.1.4 Short -| Type | Size | Range | -|----------|---------|----------------------------| -| `short` | 2 bytes | at least -32,767 to 32,767 | -| `ushort` | 2 bytes | 0 to at least 65,535 | +| Type | Size | Range | +|----------|----------|----------------------------| +| `short` | 2+ bytes | at least -32,767 to 32,767 | +| `ushort` | 2+ bytes | 0 to at least 65,535 | ### 2.4.1.5 Guaranteed-size Signed Integers -| Type | Size | Range | -|---------|---------|------------------------------------------------------------------| -| `int8` | 1 byte | at least -127 to 127 | -| `int16` | 2 bytes | at least -32,767 to 32,767 | -| `int32` | 4 bytes | at least -2,147,483,647 to 2,147,483,647 | -| `int64` | 8 bytes | at least -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 | +| Type | Size | Range | +|---------|----------|------------------------------------------------------------------| +| `int8` | 1+ byte | at least -127 to 127 | +| `int16` | 2+ bytes | at least -32,767 to 32,767 | +| `int32` | 4+ bytes | at least -2,147,483,647 to 2,147,483,647 | +| `int64` | 8+ bytes | at least -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 | ### 2.4.1.6 Guaranteed-size Unsigned Integers -| Type | Size | Range | -|----------|---------|------------------------------------------| -| `uint8` | 1 byte | 0 to at least 255 | -| `uint16` | 2 bytes | 0 to at least 65,535 | -| `uint32` | 4 bytes | 0 to at least 4,294,967,295 | -| `uint64` | 8 bytes | 0 to at least 18,446,744,073,709,551,615 | +| Type | Size | Range | +|----------|----------|------------------------------------------| +| `uint8` | 1+ byte | 0 to at least 255 | +| `uint16` | 2+ bytes | 0 to at least 65,535 | +| `uint32` | 4+ bytes | 0 to at least 4,294,967,295 | +| `uint64` | 8+ bytes | 0 to at least 18,446,744,073,709,551,615 | ### 2.4.1.7 Floating Points @@ -84,9 +84,9 @@ For more information, please refer to [size_t](https://en.cppreference.com/w/c/t ### 2.4.1.9 Booleans -| Type | Size | Values | -|--------|--------|---------------| -| `bool` | 1 byte | true or false | +| Type | Size | Values | +|--------|-------|---------------| +| `bool` | 1 bit | true or false | ### 2.4.1.10 Unicode Characters