Comments (3)
通常在C语言中,我们建议在宏上加括弧以避免副作用,尤其是运算符优先级引起的。但是就WORD_LENGTH来说,后继所有的使用都不存在这样的问题。例如:
#include <stdio.h>
#define WORD_LENGTH sizeof(int)*8
int main(int argc, char** argv) {
printf("5 mod WL = %lu, 1<<(5 mod WL) = %d\n", 5 % WORD_LENGTH, 1 << (5 % WORD_LENGTH));
}
[xinyul@f45c89ba9a29:~/temp] $ gcc foo.c -Wall -o foo
[xinyul@f45c89ba9a29:~/temp] $ ./foo
5 mod WL = 8, 1<<(5 mod WL) = 256
from algoxy.
还是不对啊?
#define WL sizeof(int)*8
TEST()
{
ASSERT_EQ(5 % WL, 5 % (sizeof(int) * 8));
}
Expected: 5 % sizeof(int)*8
Which is: 8
To be equal to: 5 % (sizeof(int) * 8)
Which is: 5
from algoxy.
非常感谢。%和*优先级相同,5 % sizeof(int) * 8 会先计算%,造成错误。
已修正
AlgoXY/others/preface/src/minfree.c
Line 24 in b6c85ed
from algoxy.
Related Issues (20)
- 前言练习题 typo HOT 1
- 前言typo HOT 1
- typo in 1.2.5节 HOT 1
- 3.3用词商榷 HOT 2
- typo in 红黑树 HOT 1
- 4.0.2树旋转的理解 HOT 2
- typo in 4.1定义 HOT 1
- 关于红黑树的插入 HOT 1
- 红黑树删除公式4.13 HOT 2
- Contributing Counting sort HOT 1
- Contributed Counting Sort HOT 2
- Support LuaLaTex HOT 6
- Improve CN font settings HOT 2
- Improve figure quality HOT 3
- Add page break between preface and TOC HOT 1
- 想将《算法新解》重新排版,纳入到开放式结构化示例图书中 HOT 1
- Break chapter 14 - search into two chapters HOT 1
- Add page reference for answers HOT 1
- 关于1.13.6答案的除法部分 HOT 1
- Support LaTeX workshop / vscode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algoxy.