Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve compiler compatibility and warnings #647

Merged
merged 3 commits into from
Dec 20, 2024

Conversation

tayne3
Copy link
Contributor

@tayne3 tayne3 commented Dec 10, 2024

变更内容

  • 添加 __GNUC_PREREQ 检查以支持原子操作(需要 GCC 4.1+)
  • gettick_ms() 中添加显式类型转换以修复整数溢出风险
  • 消除未使用变量/函数的编译警告

Changes

  • Add __GNUC_PREREQ check for atomic operations (requires GCC 4.1+)
  • Fix integer overflow risk in gettick_ms() with explicit type casting
  • Eliminate unused variable/function warnings

tayne3 added 3 commits December 10, 2024 10:56
- Replace GNUC macro check with __GNUC_PREREQ(4, 1) for more precise version control
- Add fallback definition for __GNUC_PREREQ macro when not available
- Add explicit (unsigned int) casting to tv_sec and tv_nsec/tv_usec calculations to prevent potential integer overflow
- Add (void) cast and inline qualifier to eliminate unused warnings
@@ -57,7 +57,7 @@ static inline bool atomic_flag_test_and_set(atomic_flag* p) {
#define ATOMIC_INC InterlockedIncrement
#define ATOMIC_DEC InterlockedDecrement

#elif defined(__GNUC__)
#elif __GNUC_PREREQ(4, 1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libhv限定了gcc编译器版本需要>=4.8,所以这里判断gcc版本我觉得没有太大必要性

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我明白你的意思。不过,我从使用者的角度来看,我有项目仍在使用 GCC 4.1 以下的版本,使用 libhv 库时需要进行移植。

为了提高库的兼容性,我希望最好能够保留这段代码。

@ithewei ithewei merged commit fd2ad28 into ithewei:master Dec 20, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants