* linux/macros.h(new) and linux/list.h(mod) ... @ 2001-07-05 20:57 Davide Libenzi 2001-07-05 21:31 ` David Woodhouse 2001-07-05 22:03 ` Kai Germaschewski 0 siblings, 2 replies; 22+ messages in thread From: Davide Libenzi @ 2001-07-05 20:57 UTC (permalink / raw) To: linux-kernel [-- Attachment #1: Type: text/plain, Size: 292 bytes --] This patch add a new linux/macros.h that is supposed to host utility macros that otherwise developers are forced to define in their files. This version contain only min(), max() and abs(). The other change is to linux/list.h by adding two members list_first() and list_last(). - Davide [-- Attachment #2: misc.diff --] [-- Type: application/octet-stream, Size: 1077 bytes --] diff -NBbru linux-2.4.6.vanilla/include/linux/list.h linux-2.4.6/include/linux/list.h --- linux-2.4.6.vanilla/include/linux/list.h Fri Feb 16 16:06:17 2001 +++ linux-2.4.6/include/linux/list.h Mon Jul 2 16:14:27 2001 @@ -148,6 +148,10 @@ */ #define list_for_each(pos, head) \ for (pos = (head)->next; pos != (head); pos = pos->next) + +#define list_first(head) (((head)->next != (head)) ? (head)->next: (struct list_head *) 0) + +#define list_last(head) (((head)->prev != (head)) ? (head)->prev: (struct list_head *) 0) #endif /* __KERNEL__ || _LVM_H_INCLUDE */ diff -NBbru linux-2.4.6.vanilla/include/linux/macros.h linux-2.4.6/include/linux/macros.h --- linux-2.4.6.vanilla/include/linux/macros.h Wed Dec 31 16:00:00 1969 +++ linux-2.4.6/include/linux/macros.h Wed Jul 4 16:41:31 2001 @@ -0,0 +1,19 @@ +#ifndef _LINUX_MACROS_H +#define _LINUX_MACROS_H + + +#ifndef min +#define min(a, b) (((a) < (b)) ? (a): (b)) +#endif + +#ifndef max +#define max(a, b) (((a) > (b)) ? (a): (b)) +#endif + +#ifndef abs +#define abs(a) (((a) > 0) ? (a): -(a)) +#endif + + + +#endif ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 20:57 linux/macros.h(new) and linux/list.h(mod) Davide Libenzi @ 2001-07-05 21:31 ` David Woodhouse 2001-07-05 21:45 ` Davide Libenzi 2001-07-05 22:03 ` Kai Germaschewski 1 sibling, 1 reply; 22+ messages in thread From: David Woodhouse @ 2001-07-05 21:31 UTC (permalink / raw) To: Davide Libenzi; +Cc: linux-kernel davidel@xmailserver.org said: > This patch add a new linux/macros.h that is supposed to host utility > macros that otherwise developers are forced to define in their files. > This version contain only min(), max() and abs(). Consider min(x++,y++). Try: #define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_y:_x; }) #define max(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_x:_y; }) -- dwmw2 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:31 ` David Woodhouse @ 2001-07-05 21:45 ` Davide Libenzi 2001-07-05 21:54 ` Hua Zhong ` (3 more replies) 0 siblings, 4 replies; 22+ messages in thread From: Davide Libenzi @ 2001-07-05 21:45 UTC (permalink / raw) To: David Woodhouse; +Cc: linux-kernel On 05-Jul-2001 David Woodhouse wrote: > > davidel@xmailserver.org said: >> This patch add a new linux/macros.h that is supposed to host utility >> macros that otherwise developers are forced to define in their files. >> This version contain only min(), max() and abs(). > > Consider min(x++,y++). Try: > >#define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_y:_x; >#}) >#define max(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_x:_y; >#}) Yep, it's better. - Davide ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:45 ` Davide Libenzi @ 2001-07-05 21:54 ` Hua Zhong 2001-07-05 21:58 ` David Woodhouse 2001-07-05 22:06 ` Davide Libenzi 2001-07-05 22:10 ` J . A . Magallon ` (2 subsequent siblings) 3 siblings, 2 replies; 22+ messages in thread From: Hua Zhong @ 2001-07-05 21:54 UTC (permalink / raw) To: Davide Libenzi; +Cc: David Woodhouse, linux-kernel Doesn't it add more overhead? I think using inline functions are much better. Yes you have to define it for different types (char, short, int, long, signed/unsigned). > Yep, it's better. > > > - Davide ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:54 ` Hua Zhong @ 2001-07-05 21:58 ` David Woodhouse 2001-07-05 22:20 ` Hua Zhong 2001-07-05 22:06 ` Davide Libenzi 1 sibling, 1 reply; 22+ messages in thread From: David Woodhouse @ 2001-07-05 21:58 UTC (permalink / raw) To: Hua Zhong; +Cc: Davide Libenzi, linux-kernel huaz@cs.columbia.edu said: > Doesn't it add more overhead? I think using inline functions are > much better. Why should it add overhead? Even the most naïve compiler ought to generate the same code, surely? I must admit I haven't looked hard at the output - it didn't even occur to me that it might produce suboptimal code. > Yes you have to define it for different types (char, short, int, > long, signed/unsigned). Unfortunately, this being C means that you can't call them all by the same name. If I have to use unsigned_long_max(x,y) I'd rather type it out myself :) -- dwmw2 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:58 ` David Woodhouse @ 2001-07-05 22:20 ` Hua Zhong 0 siblings, 0 replies; 22+ messages in thread From: Hua Zhong @ 2001-07-05 22:20 UTC (permalink / raw) To: David Woodhouse; +Cc: Hua Zhong, Davide Libenzi, linux-kernel -> From David Woodhouse <dwmw2@infradead.org> : > > huaz@cs.columbia.edu said: > > Doesn't it add more overhead? I think using inline functions are > > much better. > > Why should it add overhead? Even the most naïve compiler ought to generate > the same code, surely? I must admit I haven't looked hard at the output - > it didn't even occur to me that it might produce suboptimal code. right, gcc -O2 does produce the same code (but -O does not). > > > Yes you have to define it for different types (char, short, int, > > long, signed/unsigned). > > Unfortunately, this being C means that you can't call them all by the same > name. If I have to use unsigned_long_max(x,y) I'd rather type it out myself > :) Oops, I must be sleeping at that time :-) > -- > dwmw2 > > ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:54 ` Hua Zhong 2001-07-05 21:58 ` David Woodhouse @ 2001-07-05 22:06 ` Davide Libenzi 1 sibling, 0 replies; 22+ messages in thread From: Davide Libenzi @ 2001-07-05 22:06 UTC (permalink / raw) To: Hua Zhong; +Cc: linux-kernel, David Woodhouse On 05-Jul-2001 Hua Zhong wrote: > > Doesn't it add more overhead? I think using inline functions are much > better. > Yes you have to define it for different types (char, short, int, long, > signed/unsigned). Yes it does. Personally I know that min, max, etc... are macros and I never use unary operators inside. Maybe a "unsafe" __max() and a "safe" max() could coexist. - Davide ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:45 ` Davide Libenzi 2001-07-05 21:54 ` Hua Zhong @ 2001-07-05 22:10 ` J . A . Magallon 2001-07-05 22:33 ` Daniel Phillips 2001-07-05 22:43 ` David Woodhouse 3 siblings, 0 replies; 22+ messages in thread From: J . A . Magallon @ 2001-07-05 22:10 UTC (permalink / raw) To: Davide Libenzi; +Cc: David Woodhouse, linux-kernel On 20010705 Davide Libenzi wrote: > >On 05-Jul-2001 David Woodhouse wrote: >> >> davidel@xmailserver.org said: >>> This patch add a new linux/macros.h that is supposed to host utility >>> macros that otherwise developers are forced to define in their files. >>> This version contain only min(), max() and abs(). >> >> Consider min(x++,y++). Try: >> >>#define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_y:_x; >>#}) >>#define max(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_x:_y; >>#}) > >Yep, it's better. And there could be others also usefull: #define ztst(x,y) (x ?: y) // `x' if that is nonzero; otherwise, of `y' If g++ extensions worked in plain C, you just could write: #define min(x,y) (x <? y) #define max(x,y) (x >? y) -- J.A. Magallon # Let the source be with you... mailto:jamagallon@able.es Mandrake Linux release 8.1 (Cooker) for i586 Linux werewolf 2.4.6-ac1 #2 SMP Thu Jul 5 01:15:49 CEST 2001 i686 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:45 ` Davide Libenzi 2001-07-05 21:54 ` Hua Zhong 2001-07-05 22:10 ` J . A . Magallon @ 2001-07-05 22:33 ` Daniel Phillips 2001-07-05 22:43 ` David Woodhouse 3 siblings, 0 replies; 22+ messages in thread From: Daniel Phillips @ 2001-07-05 22:33 UTC (permalink / raw) To: Davide Libenzi, David Woodhouse; +Cc: linux-kernel On Thursday 05 July 2001 23:45, Davide Libenzi wrote: > On 05-Jul-2001 David Woodhouse wrote: > > davidel@xmailserver.org said: > >> This patch add a new linux/macros.h that is supposed to host utility > >> macros that otherwise developers are forced to define in their files. > >> This version contain only min(), max() and abs(). > > > > Consider min(x++,y++). Try: > > > >#define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); > > (_x>_y)?_y:_x; #}) > >#define max(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); > > (_x>_y)?_x:_y; #}) > > Yep, it's better. This program prints garbage: #define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_y:_x; }) int main (void) { int _x = 3, _y = 4; printf("%i\n", min(_x, _y)); return 0; } -- Daniel ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 21:45 ` Davide Libenzi ` (2 preceding siblings ...) 2001-07-05 22:33 ` Daniel Phillips @ 2001-07-05 22:43 ` David Woodhouse 2001-07-05 22:53 ` Davide Libenzi 2001-07-05 22:57 ` Alan Cox 3 siblings, 2 replies; 22+ messages in thread From: David Woodhouse @ 2001-07-05 22:43 UTC (permalink / raw) To: Daniel Phillips; +Cc: Davide Libenzi, linux-kernel phillips@bonn-fries.net said: > This program prints garbage: > #define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_y:_x; }) > int main (void) { > int _x = 3, _y = 4; > printf("%i\n", min(_x, _y)); > return 0; > } Life's a bitch. cf. get_user(__ret_gu, __val_gu); (on i386) Time to invent a gcc extension which gives us unique names? :) -- dwmw2 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 22:43 ` David Woodhouse @ 2001-07-05 22:53 ` Davide Libenzi 2001-07-05 23:23 ` J . A . Magallon 2001-07-05 22:57 ` Alan Cox 1 sibling, 1 reply; 22+ messages in thread From: Davide Libenzi @ 2001-07-05 22:53 UTC (permalink / raw) To: David Woodhouse; +Cc: linux-kernel, Daniel Phillips On 05-Jul-2001 David Woodhouse wrote: > > phillips@bonn-fries.net said: >> This program prints garbage: >> #define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); >> #(_x>_y)?_y:_x; }) >> int main (void) { >> int _x = 3, _y = 4; >> printf("%i\n", min(_x, _y)); >> return 0; >> } > > Life's a bitch. > cf. get_user(__ret_gu, __val_gu); (on i386) > > Time to invent a gcc extension which gives us unique names? :) Something like ::(x) to move up one level the name resolution for example. - Davide ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 22:53 ` Davide Libenzi @ 2001-07-05 23:23 ` J . A . Magallon 0 siblings, 0 replies; 22+ messages in thread From: J . A . Magallon @ 2001-07-05 23:23 UTC (permalink / raw) To: Davide Libenzi; +Cc: David Woodhouse, linux-kernel, Daniel Phillips On 20010706 Davide Libenzi wrote: > >On 05-Jul-2001 David Woodhouse wrote: >> >> phillips@bonn-fries.net said: >>> This program prints garbage: >>> #define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); >>> #(_x>_y)?_y:_x; }) >>> int main (void) { >>> int _x = 3, _y = 4; >>> printf("%i\n", min(_x, _y)); >>> return 0; >>> } >> >> Life's a bitch. >> cf. get_user(__ret_gu, __val_gu); (on i386) >> >> Time to invent a gcc extension which gives us unique names? :) > >Something like ::(x) to move up one level the name resolution for example. > Tell gcc people to support <? and >? in C besides C++. -- J.A. Magallon # Let the source be with you... mailto:jamagallon@able.es Mandrake Linux release 8.1 (Cooker) for i586 Linux werewolf 2.4.6-ac1 #2 SMP Thu Jul 5 01:15:49 CEST 2001 i686 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 22:43 ` David Woodhouse 2001-07-05 22:53 ` Davide Libenzi @ 2001-07-05 22:57 ` Alan Cox 2001-07-05 23:05 ` Matthew Dharm ` (3 more replies) 1 sibling, 4 replies; 22+ messages in thread From: Alan Cox @ 2001-07-05 22:57 UTC (permalink / raw) To: David Woodhouse; +Cc: Daniel Phillips, Davide Libenzi, linux-kernel > Life's a bitch. > cf. get_user(__ret_gu, __val_gu); (on i386) > > Time to invent a gcc extension which gives us unique names? :) #define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) #define __magic_minfoo(A,B,C,D) \ { typeof(A) C = (A) .... } Alan ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 22:57 ` Alan Cox @ 2001-07-05 23:05 ` Matthew Dharm 2001-07-05 23:07 ` Alan Cox 2001-07-05 23:08 ` David Woodhouse ` (2 subsequent siblings) 3 siblings, 1 reply; 22+ messages in thread From: Matthew Dharm @ 2001-07-05 23:05 UTC (permalink / raw) To: Alan Cox; +Cc: David Woodhouse, Daniel Phillips, Davide Libenzi, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1089 bytes --] Better, but throwing __FILE__ in there would be good too... Come to think of it, tho, we have multiple files named the same thing in multiple places on the kernel tree... even __var##__LINE__##__FILE__ isn't _guaranteed_ to be unique. Matt On Thu, Jul 05, 2001 at 11:57:11PM +0100, Alan Cox wrote: > > Life's a bitch. > > cf. get_user(__ret_gu, __val_gu); (on i386) > > > > Time to invent a gcc extension which gives us unique names? :) > > #define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) > > #define __magic_minfoo(A,B,C,D) \ > { typeof(A) C = (A) .... } > > > Alan > > - > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- Matthew Dharm Home: mdharm-usb@one-eyed-alien.net Maintainer, Linux USB Mass Storage Driver Ye gods! I have feet??! -- Dust Puppy User Friendly, 12/4/1997 [-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --] ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 23:05 ` Matthew Dharm @ 2001-07-05 23:07 ` Alan Cox 0 siblings, 0 replies; 22+ messages in thread From: Alan Cox @ 2001-07-05 23:07 UTC (permalink / raw) To: Matthew Dharm Cc: Alan Cox, David Woodhouse, Daniel Phillips, Davide Libenzi, linux-kernel > Better, but throwing __FILE__ in there would be good too... Totally inappropriate. These are not global variables and a filename is not legal variable namespace anyway ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 22:57 ` Alan Cox 2001-07-05 23:05 ` Matthew Dharm @ 2001-07-05 23:08 ` David Woodhouse 2001-07-06 1:51 ` Arnaldo Carvalho de Melo 2001-07-05 23:21 ` Davide Libenzi 2001-07-06 17:38 ` Neil Booth 3 siblings, 1 reply; 22+ messages in thread From: David Woodhouse @ 2001-07-05 23:08 UTC (permalink / raw) To: Alan Cox; +Cc: Daniel Phillips, Davide Libenzi, linux-kernel #define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) #define __magic_minfoo(A,B,C,D) \ ({ typeof(A) C = (A); typeof(B) D = (B); C>D?D:C; }) void main(void) { int __var11=5, __var211=7; printf("min(%d,%d) = %d (should be 11: %d)\n", __var11, __var211, min(__var11, __var211), __LINE__); } -- dwmw2 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 23:08 ` David Woodhouse @ 2001-07-06 1:51 ` Arnaldo Carvalho de Melo 0 siblings, 0 replies; 22+ messages in thread From: Arnaldo Carvalho de Melo @ 2001-07-06 1:51 UTC (permalink / raw) To: David Woodhouse; +Cc: Alan Cox, Daniel Phillips, Davide Libenzi, linux-kernel Em Fri, Jul 06, 2001 at 12:08:55AM +0100, David Woodhouse escreveu: > > #define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) > > #define __magic_minfoo(A,B,C,D) \ > ({ typeof(A) C = (A); typeof(B) D = (B); C>D?D:C; }) > > void main(void) > { > int __var11=5, __var211=7; > > printf("min(%d,%d) = %d (should be 11: %d)\n", __var11, __var211, min(__var11, __var211), __LINE__); > } Have you looked at the preprocessor output? [acme@brinquedo /tmp]$ gcc -E a.c -o - # or 'cpp < a.c' # 1 "a.c" void main(void) { int __var11=5, __var211=7; printf("min(%d,%d) = %d (should be 11: %d)\n", __var11, __var211, + ({ typeof( __var11 ) __var__LINE__ = ( __var11 ); typeof( __var211 ) __var2__LINE__ = ( __var211 ); __var__LINE__ > __var2__LINE__ ? __var2__LINE__ : __var__LINE__ ; }) , 11); } I didn't found a way to generate unique variable names using __LINE__ - Arnaldo ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 22:57 ` Alan Cox 2001-07-05 23:05 ` Matthew Dharm 2001-07-05 23:08 ` David Woodhouse @ 2001-07-05 23:21 ` Davide Libenzi [not found] ` <0107060149080M.03760@starship> 2001-07-06 17:38 ` Neil Booth 3 siblings, 1 reply; 22+ messages in thread From: Davide Libenzi @ 2001-07-05 23:21 UTC (permalink / raw) To: Alan Cox; +Cc: linux-kernel, Daniel Phillips, David Woodhouse On 05-Jul-2001 Alan Cox wrote: >> Life's a bitch. >> cf. get_user(__ret_gu, __val_gu); (on i386) >> >> Time to invent a gcc extension which gives us unique names? :) > >#define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) > >#define __magic_minfoo(A,B,C,D) \ > { typeof(A) C = (A) .... } Anyway I think that : int _a = 5; for (;;) { int _a = _a; ... } must : 1) assign the upper level value of _a or : 2) generate an compiler error - Davide ^ permalink raw reply [flat|nested] 22+ messages in thread
[parent not found: <0107060149080M.03760@starship>]
* Re: linux/macros.h(new) and linux/list.h(mod) ... [not found] ` <0107060149080M.03760@starship> @ 2001-07-05 23:54 ` Daniel Phillips 0 siblings, 0 replies; 22+ messages in thread From: Daniel Phillips @ 2001-07-05 23:54 UTC (permalink / raw) To: Davide Libenzi; +Cc: David Woodhouse, linux-kernel On Friday 06 July 2001 01:49, you wrote: > On Friday 06 July 2001 01:21, Davide Libenzi wrote: > > On 05-Jul-2001 Alan Cox wrote: > > >> Life's a bitch. > > >> cf. get_user(__ret_gu, __val_gu); (on i386) > > >> > > >> Time to invent a gcc extension which gives us unique names? :) > > > > > >#define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) > > > > > >#define __magic_minfoo(A,B,C,D) \ > > > { typeof(A) C = (A) .... } > > > > Anyway I think that : > > > > int _a = 5; > > > > for (;;) { > > int _a = _a; > > ... > > } > > > > must : > > > > 1) assign the upper level value of _a > > > > or : > > > > 2) generate an compiler error > > Well, I happen to agree with you, but in this case, c's scope rules > are stupidly broken, they are not going to change, and we have to > live with it ;-) > > -- > Daniel ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 22:57 ` Alan Cox ` (2 preceding siblings ...) 2001-07-05 23:21 ` Davide Libenzi @ 2001-07-06 17:38 ` Neil Booth 2001-07-06 22:02 ` Arnaldo Carvalho de Melo 3 siblings, 1 reply; 22+ messages in thread From: Neil Booth @ 2001-07-06 17:38 UTC (permalink / raw) To: Alan Cox; +Cc: David Woodhouse, Daniel Phillips, Davide Libenzi, linux-kernel Alan Cox wrote:- > #define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) > > #define __magic_minfoo(A,B,C,D) \ > { typeof(A) C = (A) .... } No, that's buggy. You need an extra level of indirection to expand __LINE__. Arguments to ## are inserted in-place without expansion. Neil. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-06 17:38 ` Neil Booth @ 2001-07-06 22:02 ` Arnaldo Carvalho de Melo 0 siblings, 0 replies; 22+ messages in thread From: Arnaldo Carvalho de Melo @ 2001-07-06 22:02 UTC (permalink / raw) To: Neil Booth Cc: Alan Cox, David Woodhouse, Daniel Phillips, Davide Libenzi, linux-kernel Em Fri, Jul 06, 2001 at 06:38:04PM +0100, Neil Booth escreveu: > Alan Cox wrote:- > > > #define min(a,b) __magic_minfoo(a,b, __var##__LINE__, __var2##__LINE__) > > > > #define __magic_minfoo(A,B,C,D) \ > > { typeof(A) C = (A) .... } > > No, that's buggy. You need an extra level of indirection to expand > __LINE__. Arguments to ## are inserted in-place without expansion. yes, so lets try with another indirection and see if I'm missing something that you could clarify :) [acme@brinquedo __attribute__]$ cat b.c #define _min(a,b,line) __magic_minfoo(a,b, __var##line, __var2##line) #define min(a,b) _min(a,b,__LINE__) #define __magic_minfoo(A,B,C,D) \ ({ typeof(A) C = (A); typeof(B) D = (B); C>D?D:C; }) void main(void) { int __var11=5, __var211=7; printf("min(%d,%d) = %d (should be 11: %d)\n", __var11, __var211, min(__var11, __var211), __LINE__); } [acme@brinquedo __attribute__]$ cpp < b.c # 1 "" void main(void) { int __var11=5, __var211=7; printf("min(%d,%d) = %d (should be 11: %d)\n", __var11, __var211, ({ typeof( __var11 ) __var__LINE__ = ( __var11 ); typeof( __var211 ) __var2__LINE__ = ( __var211 ); __var__LINE__ > __var2__LINE__ ? __var2__LINE__ : __var__LINE__ ; }) , 12); } [acme@brinquedo __attribute__]$ - Arnaldo ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: linux/macros.h(new) and linux/list.h(mod) ... 2001-07-05 20:57 linux/macros.h(new) and linux/list.h(mod) Davide Libenzi 2001-07-05 21:31 ` David Woodhouse @ 2001-07-05 22:03 ` Kai Germaschewski 1 sibling, 0 replies; 22+ messages in thread From: Kai Germaschewski @ 2001-07-05 22:03 UTC (permalink / raw) To: Davide Libenzi; +Cc: linux-kernel On Thu, 5 Jul 2001, Davide Libenzi wrote: > This patch add a new linux/macros.h that is supposed to host utility macros > that otherwise developers are forced to define in their files. > This version contain only min(), max() and abs(). It's a good old tradition to put macros in uppercase letters. This would have avoided one fatal error in your patch, the conflict with the gcc built-in int abs(int); which has it's prototype in include/linux/kernel.h. There's places which depend on this and would break with your macro. Also, unless you have more macros in mind, it may make sense to just place MIN, MAX in kernel.h and of course to remove similar macro definitions throughout the kernel and replace them by the commonly defined ones. --Kai ^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2001-07-06 22:02 UTC | newest] Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-07-05 20:57 linux/macros.h(new) and linux/list.h(mod) Davide Libenzi 2001-07-05 21:31 ` David Woodhouse 2001-07-05 21:45 ` Davide Libenzi 2001-07-05 21:54 ` Hua Zhong 2001-07-05 21:58 ` David Woodhouse 2001-07-05 22:20 ` Hua Zhong 2001-07-05 22:06 ` Davide Libenzi 2001-07-05 22:10 ` J . A . Magallon 2001-07-05 22:33 ` Daniel Phillips 2001-07-05 22:43 ` David Woodhouse 2001-07-05 22:53 ` Davide Libenzi 2001-07-05 23:23 ` J . A . Magallon 2001-07-05 22:57 ` Alan Cox 2001-07-05 23:05 ` Matthew Dharm 2001-07-05 23:07 ` Alan Cox 2001-07-05 23:08 ` David Woodhouse 2001-07-06 1:51 ` Arnaldo Carvalho de Melo 2001-07-05 23:21 ` Davide Libenzi [not found] ` <0107060149080M.03760@starship> 2001-07-05 23:54 ` Daniel Phillips 2001-07-06 17:38 ` Neil Booth 2001-07-06 22:02 ` Arnaldo Carvalho de Melo 2001-07-05 22:03 ` Kai Germaschewski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).