You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem - current coding standards explicitly discourages
use of int, char, short etc, and recommends fixed types instead.
This is overly pedantic. The real problem, and the only problem we have
with types concerning portability, the inappropriate use of `long` is
too easy to overlook.
Thus,un-deprecate the types that are portable, for all practical purpose
i.e int, short, long long. Warning that char might be unsigned, though,
all compilers have appropriate flags.
Yet, use strongly wording to deprecate long and ulong, those are the types
that create real portability problems.
Copy file name to clipboardExpand all lines: CODING_STANDARDS.md
+13-14Lines changed: 13 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -360,21 +360,20 @@ For example:
360
360
my_function(thd, db_name);
361
361
```
362
362
363
-
### Types
363
+
### Integer types
364
364
365
-
In general the usage of types such as `char`, `int` and `long` should be discouraged but there are shortened versions of the unsigned variants available for these in `my_global.h`.
366
-
They can be different sizes across platforms and `char` can be either unsigned or signed depending on platform, and therefore are not portable.
367
-
Instead these should be used as appropriate:
365
+
The usage of types `long` and `unsigned long` (and its `ulong` alias)
366
+
in new code is *strongly* discouraged. Its use brings no advantages,
367
+
only portability problems between Windows and Unixes.
368
368
369
-
* 8-bit signed / unsigned int -> `int8` / `uint8`
370
-
* 16-bit signed / unsigned int -> `int16` / `uint16`
371
-
* 32-bit signed / unsigned int -> `int32` / `uint32`
372
-
* 64-bit signed / unsigned int -> `int64` / `uint64`
373
-
* Integer file descriptor -> `File`
374
-
* Integer socket descriptor -> `my_socket`
369
+
Instead of using `long`, use `size_t` and `ptrdiff_t` where appropriate,
370
+
buffer sizes for example. For integer socket descriptor use `my_socket`.
375
371
376
-
`size_t` and `ptrdiff_t` are used in the source where appropriate, buffer sizes for example.
377
-
It should be noted that these are implementation dependent but are useful when used in the correct context.
372
+
You may use types with fixed length, int32_t and similar, too. Yet, on all platforms we currently support,
373
+
* `char` is 8 bit
374
+
* `short` is 16 bit
375
+
* `int` is 32bit
376
+
* `long long` is 64bit
378
377
379
-
Further types can be found in the `include/` directory files.
380
-
There are also general utility functions in `mysys`.
378
+
and the above is not likely to change for the decades to come. Those types are safe to use. When using `char`
379
+
though, be aware that its signdness can depend on compiler flags, so do not assume it can take negative values.
0 commit comments