docs: enhanced document readability with the help of ChatGPT

This commit is contained in:
DarkSharpness
2024-07-23 17:44:41 +08:00
parent d3572cc9dc
commit edb0dae127
2 changed files with 46 additions and 58 deletions

View File

@ -1,9 +1,9 @@
# Some common mistakes
# Some Common Mistakes
## Bit-width mismatch
## Bit-width Mismatch
That is, the bit-width of the LHS and RHS of an assignment operation are different.
For example, the following code will result in compile error:
This occurs when the bit-width of the left-hand side (LHS) and right-hand side (RHS) of an assignment operation are different.
For example, the following code will result in a compile error:
```cpp
Register <8> r1;
@ -11,32 +11,28 @@ Register <16> r2;
r1 <= r2; // Error: bit-width mismatch
```
## Register/Wire passed by value
## Register/Wire Passed by Value
Register/Wire can be only passed by reference. We forbid
the copy/move constructor for Register/Wire to avoid misuse.
Register/Wire can only be passed by reference. We forbid the copy/move constructor for Register/Wire to prevent misuse.
This may cause some error in the lambda function of a wire.
This may cause errors in the lambda function of a wire.
```cpp
Register <8> r1;
Wire <8> w1 = [&]() { return r1; };
```
To fix this issue, you may return by reference,
or use + operator to convert the value to bit type.
To fix this issue, you may return by reference or use the + operator to convert the value to a bit type.
```cpp
Register <8> r1;
Wire <8> w1 = [&]() -> auto & { return r1; };
Wire <8> w2 = [&]() { return +r1; };
Wire <8> w2 = [&]() { return +r1; }; // +r1 will return Bit<8>b
```
## C-array as member variable
## C-array as Member Variable
We do not support C-array as member variable for synchronization.
Our C++ static reflection library do not support parsing
C-array as member variable currently.
We do not support C-arrays as member variables for synchronization. Our C++ static reflection library does not currently support parsing C-arrays as member variables.
Always use `std::array` instead.
@ -47,6 +43,6 @@ struct NeedToSync {
};
```
## Some others
## Others
If you encounter some other issues, please feel free to open an issue.
If you encounter other issues, please feel free to open an issue.