Liste des Groupes | Revenir à cl c |
On 08/08/2024 17:32, Michael S wrote:Michael is correct - the OP should enable optimisation, precisely to avoid the issue you are concerned about. Without optimisation, the results are misleading - they will only show things that are /not/ involved in the conversion, swamping the useful results with code that messes about putting data on and off the stack. When optimised compilation shows that no code is generated, it is a very clear indication that no operations are needed for the conversions in question - unoptimized code hides that.
> On Thu, 8 Aug 2024 14:23:44 +0100
> Bart <bc@freeuk.com> wrote:
>> Try godbolt.org. Type in a fragment of code that does different kinds
>> of casts (it needs to be well-formed, so inside a function), and see
>> what code is produced with different C compilers.
>>
>> Use -O0 so that the code isn't optimised out of existence, and so
>> that you can more easily match it to the C ource.
>>
>>
>
>
> I'd recommend an opposite - use -O2 so the cast that does nothing
> optimized away.
>
> int foo_i2i(int x) { return (int)x; }
> int foo_u2i(unsigned x) { return (int)x; }
> int foo_b2i(_Bool x) { return (int)x; }
> int foo_d2i(double x) { return (int)x; }
The OP is curious as to what's involved when a conversion is done. Hiding or eliminating code isn't helpful in that case; the results can also be misleading:
Take this example:No, you can't see that. All you can see is garbage in, garbage out. You have to start with a function that has some meaning!
void fred(void) {
_Bool b;
int i;
i=b;
}
Unoptimised, it generates this code:
push rbp
mov rbp, rsp
mov al, byte ptr [rbp - 1]
and al, 1
movzx eax, al
mov dword ptr [rbp - 8], eax
pop rbp
ret
You can see from this that a Bool occupies one byte; it is masked to 0/1 (so it doesn't trust it to contain only 0/1), then it is widened to an int size.
With optimisation turned on, even at -O1, it produces this:Try again with:
ret
Date | Sujet | # | Auteur | |
7 Aug 24 | how cast works? | 122 | Thiago Adams | |
7 Aug 24 | Re: how cast works? | 7 | Thiago Adams | |
7 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
12 Aug 24 | Re: how cast works? | 5 | Tim Rentsch | |
12 Aug 24 | Re: how cast works? | 4 | Vir Campestris | |
12 Aug 24 | Challenge/exercise problem - signum() function | 3 | Tim Rentsch | |
12 Aug 24 | Re: Challenge/exercise problem - signum() function | 2 | Lew Pitcher | |
12 Aug 24 | Re: Challenge/exercise problem - signum() function | 1 | Tim Rentsch | |
7 Aug 24 | Re: how cast works? | 107 | Dan Purgert | |
7 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
8 Aug 24 | Re: how cast works? | 1 | Lawrence D'Oliveiro | |
8 Aug 24 | Re: how cast works? | 101 | Thiago Adams | |
8 Aug 24 | Re: how cast works? | 25 | Bart | |
8 Aug 24 | Re: how cast works? | 24 | Michael S | |
8 Aug 24 | Re: how cast works? | 1 | Thiago Adams | |
8 Aug 24 | Re: how cast works? | 22 | Bart | |
8 Aug 24 | Re: how cast works? | 5 | Thiago Adams | |
8 Aug 24 | Re: how cast works? | 1 | Thiago Adams | |
8 Aug 24 | Re: how cast works? | 2 | Bart | |
8 Aug 24 | Re: how cast works? | 1 | Thiago Adams | |
8 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
8 Aug 24 | Re: how cast works? | 16 | David Brown | |
8 Aug 24 | Re: how cast works? | 15 | Bart | |
9 Aug 24 | Re: how cast works? | 13 | David Brown | |
9 Aug 24 | Re: how cast works? | 9 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 3 | Lawrence D'Oliveiro | |
9 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 1 | James Kuyper | |
9 Aug 24 | Re: how cast works? | 5 | David Brown | |
9 Aug 24 | Re: how cast works? | 4 | Keith Thompson | |
12 Aug 24 | Re: how cast works? | 3 | Tim Rentsch | |
12 Aug 24 | Re: how cast works? | 2 | Keith Thompson | |
3 Sep 24 | Re: how cast works? | 1 | Tim Rentsch | |
9 Aug 24 | Re: how cast works? | 3 | Bart | |
9 Aug 24 | Re: how cast works? | 2 | David Brown | |
10 Aug 24 | Re: how cast works? | 1 | Bart | |
9 Aug 24 | Re: how cast works? | 1 | Lawrence D'Oliveiro | |
8 Aug 24 | Re: how cast works? | 75 | Keith Thompson | |
8 Aug 24 | Re: how cast works? | 74 | Thiago Adams | |
8 Aug 24 | Re: how cast works? | 72 | Bart | |
9 Aug 24 | Re: how cast works? | 47 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 38 | Bart | |
9 Aug 24 | Re: how cast works? | 2 | David Brown | |
12 Aug 24 | Re: how cast works? | 1 | Bart | |
9 Aug 24 | Re: how cast works? | 29 | James Kuyper | |
9 Aug 24 | Re: how cast works? | 14 | Bart | |
9 Aug 24 | Re: how cast works? | 3 | Keith Thompson | |
10 Aug 24 | Re: how cast works? | 2 | Bart | |
10 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
10 Aug 24 | Re: how cast works? | 10 | James Kuyper | |
13 Aug 24 | Re: how cast works? | 1 | David Brown | |
13 Aug 24 | Re: how cast works? | 1 | Bart | |
13 Aug 24 | Re: how cast works? | 7 | James Kuyper | |
13 Aug 24 | Re: how cast works? | 6 | Bart | |
13 Aug 24 | Re: how cast works? | 5 | Keith Thompson | |
13 Aug 24 | Re: how cast works? | 4 | Bart | |
14 Aug 24 | Re: how cast works? | 3 | Tim Rentsch | |
14 Aug 24 | Re: how cast works? | 2 | Bart | |
18 Aug 24 | Re: how cast works? | 1 | Tim Rentsch | |
9 Aug 24 | Re: how cast works? | 2 | Keith Thompson | |
10 Aug 24 | Re: how cast works? | 1 | James Kuyper | |
9 Aug 24 | Re: how cast works? | 12 | Kaz Kylheku | |
9 Aug 24 | Re: how cast works? | 9 | Keith Thompson | |
10 Aug 24 | Re: how cast works? | 8 | Kaz Kylheku | |
10 Aug 24 | Re: how cast works? | 6 | Keith Thompson | |
10 Aug 24 | Re: how cast works? | 3 | Kaz Kylheku | |
10 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
10 Aug 24 | Re: how cast works? | 1 | James Kuyper | |
10 Aug 24 | Re: how cast works? | 2 | Bart | |
13 Aug 24 | Re: how cast works? | 1 | David Brown | |
12 Aug 24 | Re: how cast works? | 1 | Tim Rentsch | |
10 Aug 24 | Re: how cast works? | 1 | James Kuyper | |
12 Aug 24 | Re: how cast works? | 1 | Tim Rentsch | |
9 Aug 24 | Re: how cast works? | 4 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 3 | Bart | |
9 Aug 24 | Re: how cast works? | 2 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 1 | Bart | |
12 Aug 24 | Re: how cast works? | 2 | Tim Rentsch | |
12 Aug 24 | Re: how cast works? | 1 | Bart | |
12 Aug 24 | Re: how cast works? | 8 | Tim Rentsch | |
12 Aug 24 | Re: how cast works? | 7 | Bart | |
12 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
12 Aug 24 | Re: how cast works? | 5 | Tim Rentsch | |
12 Aug 24 | Re: how cast works? | 4 | Keith Thompson | |
12 Aug 24 | Re: how cast works? | 3 | Ben Bacarisse | |
12 Aug 24 | Re: how cast works? | 2 | Tim Rentsch | |
12 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 24 | Thiago Adams | |
9 Aug 24 | Re: how cast works? | 2 | Bart | |
9 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 19 | David Brown | |
9 Aug 24 | Re: how cast works? | 18 | Thiago Adams | |
9 Aug 24 | Re: how cast works? | 3 | Thiago Adams | |
9 Aug 24 | Re: how cast works? | 1 | David Brown | |
9 Aug 24 | Re: how cast works? | 1 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 11 | David Brown | |
10 Aug 24 | Re: how cast works? | 10 | Bart | |
10 Aug 24 | Re: how cast works? | 9 | Thiago Adams | |
10 Aug 24 | Re: how cast works? | 8 | Bart | |
11 Aug 24 | Re: how cast works? | 7 | Thiago Adams | |
11 Aug 24 | Re: how cast works? | 6 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 3 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 2 | Keith Thompson | |
9 Aug 24 | Re: how cast works? | 1 | David Brown | |
8 Aug 24 | Re: how cast works? | 3 | Stefan Ram | |
7 Aug 24 | Re: how cast works? | 6 | Keith Thompson | |
8 Aug 24 | Re: how cast works? | 1 | Lawrence D'Oliveiro |
Les messages affichés proviennent d'usenet.