Skip to content

Commit 75eba82

Browse files
committed
add max macro defination
1 parent 2a844cf commit 75eba82

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

C and C++.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@
129129
argv 里面各个指针指向的貌似是同一段连续空间的不同位置,所以说可以从
130130
argv[0]一直覆盖到 argv[argc]
131131

132+
40、kernel中的max宏的设计有哪些考虑?
133+
(tips:如果按照直观的考虑 max 宏的定义如下:
134+
#define max(a,b) return (a)>(b)?(a):(b)
135+
但这样的定义在面对,max(a++, b++)这种调用会引入
136+
二义性,所以内核对max有改进
137+
#define max(a, b)\
138+
(typeof a) _a = a;\
139+
(typeof b) _b = b;
140+
(void) &a == &b;
141+
return _a > _b ? _a : _b)
142+
132143

133144

134145

0 commit comments

Comments
 (0)