aboutsummaryrefslogtreecommitdiff
path: root/174/index.md
blob: 7e7e5c00c7e3740562ee67db0369f9401e820b32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Title: Use fixed width integers for CSS length type
Author: rodarima
Created: Sat, 25 May 2024 23:10:31 +0000
State: closed

The current type for a CSS "length" like `80px` or `20%` is represented internally as a single `int` type, which doesn't have a fixed length. In C and C++, there is only a guarantee that an int will hold at least 16 bits, but the current assumption is that it will hold at least 32 bits.
```
| <------   integer value   ------> |

+---+ - - - +---+---+- - - - - -+---+---+---+---+
|          integer part             |   type    |
+---+ - - - +---+---+- - - - - -+---+---+---+---+
| integer part  | decimal fraction  |   type    |
+---+ - - - +---+---+- - - - - -+---+---+---+---+
 n-1          15  14              3   2  1   0

| <------ fixed point value ------> |
```

Furthermore, as we introduce more length types we are going to run out of length bits for the value itself. A simple option could be to define the length as something like this:

```c
typedef struct CssLength {
    CssLengthType type;
    union {
        int i;
        float f;
    };
} CssLength;
```

Which will duplicate the size required to store lengths to 64 bits, as the type will likely use 32 bits with padding and another 32 bits for the integer/float value (on 64 bits machines). It has the benefit that on 16 bits machines, the size will halve to 32 bits, as all members will reduce their size.

--%--
From: kalvdans
Date: Wed, 12 Jun 2024 20:44:41 +0000

As a first step maybe use `int32_t` for the type to make sure we get 32 bits even on 16-bit platforms?

--%--
From: rodarima
Date: Sat, 05 Oct 2024 17:28:01 +0000

Merged in #264