Em qui., 7 de jul. de 2022 às 08:00, Peter Eisentraut <
[email protected]> escreveu:
> On 18.05.22 15:52, Peter Eisentraut wrote:
> > On 18.05.22 01:18, Justin Pryzby wrote:
> >> Take the first one as an example. It says:
> >>
> >> GenericCosts costs;
> >> MemSet(&costs, 0, sizeof(costs));
> >>
> >> You sent a patch to change it to sizeof(GenericCosts).
> >>
> >> But it's not a pointer, so they are the same.
> >
> > This instance can more easily be written as
> >
> > costs = {0};
>
> The attached patch replaces all MemSet() calls with struct
> initialization where that is easily possible. (For example, some cases
> have to worry about padding bits, so I left those.)
>
Sounds great.
#include <stdio.h>
#include <string.h>
int main(void) {
bool nulls[4] = {0};
int i;
memset(nulls, 0, sizeof(nulls));
for(i = 0; i < 4; i++)
{
nulls[i] = 0;
}
return 1;
}
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-8], 0 // bool nulls[4] = {0}; lea
rax, [rbp-8]
mov edx, 4
mov esi, 0
mov rdi, rax
call memset
mov DWORD PTR [rbp-4], 0
jmp .L2
.L3:
mov eax, DWORD PTR [rbp-4]
cdqe
mov BYTE PTR [rbp-8+rax], 0
add DWORD PTR [rbp-4], 1
.L2:
cmp DWORD PTR [rbp-4], 3
jle .L3
mov eax, 1
leave
ret
Only one line using {0}.
+1
regards,
Ranier Vilela