antirez / antirez/sds

Improve const-correctness for read-only functions (e.g., sdslen, sdscmp)

オープン
#154 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C
スター
5.6k
フォーク
510
PR マージ指標
30日以内にマージされた PR はありません

説明

Functions that perform read-only operations, like `sdscmp`, are declared with `const sds` parameters. Due to `typedef char *sds;`, `const sds` resolves to `char * const` (a constant pointer to mutable data).
This signature incorrectly implies that the function might modify the content of the sds strings.
More importantly, it makes it impossible to pass a `const char *` (that is known to be a valid `sds` string) to these functions without a cast that discards the `const` qualifier, which fails compilation under `-Werror`.
To significantly improve const-correctness and interoperability with modern C/C++ codebases, I would like to propose introducing a new type for read-only sds strings:
``` c
typedef const char * const_sds;
```
With this new type, the signatures of read-only functions could be updated or overloaded. For example:
``` c
int sdscmp(const_sds s1, const_sds s2);
size_t sdslen(const_sds s);
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。