* void* arithmnetic @ 2007-11-29 0:05 J.A. Magallón 2007-11-29 0:22 ` Arnaldo Carvalho de Melo 2007-11-29 0:39 ` Jan Engelhardt 0 siblings, 2 replies; 7+ messages in thread From: J.A. Magallón @ 2007-11-29 0:05 UTC (permalink / raw) To: Linux-Kernel, Hi all... Since begin of the ages the build of the nvidia driver says things like this: include/asm/compat.h:210: warning: pointer of type 'void *' used in arithmetic There are several of this warnings. The code in question for this example is: static __inline__ void __user *compat_alloc_user_space(long len) { struct pt_regs *regs = task_pt_regs(current); return (void __user *)regs->rsp - len; } As this is dealing with mem blocks, I suppose it's counting in bytes, so we could do something like: return (void __user *)((u8*)regs->rsp - len); so the arithmetic knows how to inc/dec for each unity... I think the warning is correct and that void* arithmetic is undefined in C, isn't it ? TIA -- J.A. Magallon <jamagallon()ono!com> \ Software is like sex: \ It's better when it's free Mandriva Linux release 2008.1 (Cooker) for i586 Linux 2.6.23-jam01 (gcc 4.2.2 20070909 (4.2.2-0.RC.1mdv2008.0)) SMP PREEMPT 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: void* arithmnetic 2007-11-29 0:05 void* arithmnetic J.A. Magallón @ 2007-11-29 0:22 ` Arnaldo Carvalho de Melo 2007-11-29 0:39 ` Jan Engelhardt 1 sibling, 0 replies; 7+ messages in thread From: Arnaldo Carvalho de Melo @ 2007-11-29 0:22 UTC (permalink / raw) To: J.A. Magallón; +Cc: linux-kernel Em Thu, Nov 29, 2007 at 01:05:31AM +0100, J.A. Magallón escreveu: > Hi all... > > Since begin of the ages the build of the nvidia driver says things like > this: > > include/asm/compat.h:210: warning: pointer of type 'void *' used in arithmetic > > There are several of this warnings. The code in question for this example > is: > > static __inline__ void __user *compat_alloc_user_space(long len) > { > struct pt_regs *regs = task_pt_regs(current); > return (void __user *)regs->rsp - len; > } > > As this is dealing with mem blocks, I suppose it's counting in bytes, so > we could do something like: > > return (void __user *)((u8*)regs->rsp - len); > > so the arithmetic knows how to inc/dec for each unity... > I think the warning is correct and that void* arithmetic is undefined in C, > isn't it ? Yes, but not in gcc, the language the kernel is written 8) It is allowed and the size of a void is 1. -Wpointer-arith disables this. [acme@doppio ~]$ cat voidptr.c #include <stdio.h> int main(int argc, char *argv[]) { void *ptr = argv[argc - 1]; puts(ptr + 4); return 0; } [acme@doppio ~]$ gcc -Wall voidptr.c -o voidptr [acme@doppio ~]$ ./a Magallón llón [acme@doppio ~]$ gcc -Wall -Wpointer-arith voidptr.c -o voidptr voidptr.c: In function ‘main’: voidptr.c:7: warning: pointer of type ‘void *’ used in arithmetic [acme@doppio ~]$ ./a Magallón llón [acme@doppio ~]$ - Arnaldo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: void* arithmnetic 2007-11-29 0:05 void* arithmnetic J.A. Magallón 2007-11-29 0:22 ` Arnaldo Carvalho de Melo @ 2007-11-29 0:39 ` Jan Engelhardt 2007-11-29 1:19 ` Ming Lei 1 sibling, 1 reply; 7+ messages in thread From: Jan Engelhardt @ 2007-11-29 0:39 UTC (permalink / raw) To: J.A. Magallón; +Cc: Linux-Kernel, On Nov 29 2007 01:05, J.A. Magallón wrote: > >Since begin of the ages the build of the nvidia driver says things like >this: > Explicitly adding -Wpointer-arith to ones own Makefile is like admitting the code might be problematic. :-> I think sizeof(void *) == 1 is taken as granted as sizeof(int) >= 4 these days. Sigh. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: void* arithmnetic 2007-11-29 0:39 ` Jan Engelhardt @ 2007-11-29 1:19 ` Ming Lei 2007-11-29 7:38 ` Benny Halevy 0 siblings, 1 reply; 7+ messages in thread From: Ming Lei @ 2007-11-29 1:19 UTC (permalink / raw) To: Jan Engelhardt; +Cc: J.A. Magallón, Linux-Kernel, 2007/11/29, Jan Engelhardt <jengelh@computergmbh.de>: > > On Nov 29 2007 01:05, J.A. Magallón wrote: > > > >Since begin of the ages the build of the nvidia driver says things like > >this: > > > > Explicitly adding -Wpointer-arith to ones own Makefile is like > admitting the code might be problematic. :-> > > > I think sizeof(void *) == 1 is taken as granted as sizeof(int) >= 4 > these days. Sigh. sizeof(void *) == 4, sizeof(void)==1, :) > - > 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/ > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: void* arithmnetic 2007-11-29 1:19 ` Ming Lei @ 2007-11-29 7:38 ` Benny Halevy 2007-11-29 12:31 ` WANG Cong 0 siblings, 1 reply; 7+ messages in thread From: Benny Halevy @ 2007-11-29 7:38 UTC (permalink / raw) To: Ming Lei; +Cc: Jan Engelhardt, "J.A. Magallón", Linux-Kernel, On Nov. 29, 2007, 3:19 +0200, "Ming Lei" <tom.leiming@gmail.com> wrote: > 2007/11/29, Jan Engelhardt <jengelh@computergmbh.de>: >> On Nov 29 2007 01:05, J.A. Magallón wrote: >>> Since begin of the ages the build of the nvidia driver says things like >>> this: >>> >> Explicitly adding -Wpointer-arith to ones own Makefile is like >> admitting the code might be problematic. :-> >> >> >> I think sizeof(void *) == 1 is taken as granted as sizeof(int) >= 4 >> these days. Sigh. > sizeof(void *) == 4, sizeof(void)==1, :) well, sizeof(void *) == sizeof(unsigned long) maybe :) >> - >> 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/ >> > - > 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/ > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: void* arithmnetic 2007-11-29 7:38 ` Benny Halevy @ 2007-11-29 12:31 ` WANG Cong 2007-11-30 11:38 ` Geert Uytterhoeven 0 siblings, 1 reply; 7+ messages in thread From: WANG Cong @ 2007-11-29 12:31 UTC (permalink / raw) To: Benny Halevy Cc: Ming Lei, Jan Engelhardt, "J.A. Magallón", Linux-Kernel, On Thu, Nov 29, 2007 at 09:38:46AM +0200, Benny Halevy wrote: >On Nov. 29, 2007, 3:19 +0200, "Ming Lei" <tom.leiming@gmail.com> wrote: >> 2007/11/29, Jan Engelhardt <jengelh@computergmbh.de>: >>> On Nov 29 2007 01:05, J.A. Magallón wrote: >>>> Since begin of the ages the build of the nvidia driver says things like >>>> this: >>>> >>> Explicitly adding -Wpointer-arith to ones own Makefile is like >>> admitting the code might be problematic. :-> >>> >>> >>> I think sizeof(void *) == 1 is taken as granted as sizeof(int) >= 4 >>> these days. Sigh. >> sizeof(void *) == 4, sizeof(void)==1, :) >well, sizeof(void *) == sizeof(unsigned long) maybe :) I *heard* that on Win64 sizeof(void *) > sizeof(long). But it's off-topic here. ;-) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: void* arithmnetic 2007-11-29 12:31 ` WANG Cong @ 2007-11-30 11:38 ` Geert Uytterhoeven 0 siblings, 0 replies; 7+ messages in thread From: Geert Uytterhoeven @ 2007-11-30 11:38 UTC (permalink / raw) To: WANG Cong Cc: Benny Halevy, Ming Lei, Jan Engelhardt, "J.A. Magallón", Linux-Kernel, [-- Attachment #1: Type: TEXT/PLAIN, Size: 1192 bytes --] On Thu, 29 Nov 2007, WANG Cong wrote: > On Thu, Nov 29, 2007 at 09:38:46AM +0200, Benny Halevy wrote: > >On Nov. 29, 2007, 3:19 +0200, "Ming Lei" <tom.leiming@gmail.com> wrote: > >> 2007/11/29, Jan Engelhardt <jengelh@computergmbh.de>: > >>> On Nov 29 2007 01:05, J.A. Magallón wrote: > >>>> Since begin of the ages the build of the nvidia driver says things like > >>>> this: > >>>> > >>> Explicitly adding -Wpointer-arith to ones own Makefile is like > >>> admitting the code might be problematic. :-> > >>> > >>> > >>> I think sizeof(void *) == 1 is taken as granted as sizeof(int) >= 4 > >>> these days. Sigh. > >> sizeof(void *) == 4, sizeof(void)==1, :) > >well, sizeof(void *) == sizeof(unsigned long) maybe :) > > I *heard* that on Win64 sizeof(void *) > sizeof(long). But it's off-topic > here. ;-) Yes, Win64 is P64, to make sure it's incompatible with the rest of the world. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-11-30 11:38 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2007-11-29 0:05 void* arithmnetic J.A. Magallón 2007-11-29 0:22 ` Arnaldo Carvalho de Melo 2007-11-29 0:39 ` Jan Engelhardt 2007-11-29 1:19 ` Ming Lei 2007-11-29 7:38 ` Benny Halevy 2007-11-29 12:31 ` WANG Cong 2007-11-30 11:38 ` Geert Uytterhoeven
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).