[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*
From: |
Sergey Korshunoff |
Subject: |
Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1. |
Date: |
Sat, 7 Mar 2015 00:54:13 +0300 |
2015-03-06 12:48 GMT+03:00, Edmund Grimley Evans
<address@hidden>:
>> Yes, I know, but I would nevertheless prefer (0 / x) to do the same
>> thing as (y / x) when both x and y are zero at run time. That
>> potentially depends on the target architecture.
>
> To explain a bit better what I mean: On a particular architecture I
> would like each of the following programs to do the same thing when
> invoked with no arguments, which isn't required by any standard that I
> know of, but it's nice to have and easy to achieve.
>
> #include <stdio.h>
> int main(int argc, char *argv[])
> {
> int a = argc >> 1 & 127;
> int b = argc >> 8 & 127
> printf("%d\n", a / b);
> return 0;
> }
>
> #include <stdio.h>
> int main(int argc, char *argv[])
> {
> int a = argc >> 1 & 127;
> int b = argc >> 8 & 127
> printf("%d\n", a / 0);
> return 0;
> }
>
> #include <stdio.h>
> int main(int argc, char *argv[])
> {
> int a = argc >> 1 & 127;
> int b = argc >> 8 & 127;
> printf("%d\n", 0 / 0);
> return 0;
> }
>
> What those programs do does, of course, depend on the architecture.
gcc gives a warning at compilation time about dividing by zero :-)
PS: your solution with memset() is more correct.
A C standard do not say anything about realtion betwean sizeof(int)
and any other integer size.
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., (continued)
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Edmund Grimley Evans, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Sergey Korshunoff, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Sergey Korshunoff, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Edmund Grimley Evans, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Sergey Korshunoff, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Edmund Grimley Evans, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Vincent Lefevre, 2015/03/06
Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Vincent Lefevre, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Edmund Grimley Evans, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Edmund Grimley Evans, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1.,
Sergey Korshunoff <=
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Vincent Lefevre, 2015/03/06
- Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1., Edmund Grimley Evans, 2015/03/07
- Prev by Date:
Re: [Tinycc-devel] revert 4b92dbf9237c5712d2ab3a2ce3fab7904c85dad2 please
- Next by Date:
Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1.
- Previous by thread:
Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1.
- Next by thread:
Re: [Tinycc-devel] [PATCH] tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1.
- Index(es):