Re: scripts/basic/bin2c: Complete error handling in main()

From: Masahiro Yamada
Date: Wed Nov 02 2016 - 14:28:01 EST


2016-11-03 2:48 GMT+09:00 SF Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>:
>> Is replacing printf("\"\n") with puts("\"") optimization?
>
> Is the difference relevant if an âordinaryâ string is passed instead of
> a format string?

I think GCC does the replacement automatically
unless -ffreestanding option is given.


With a quick test, I got the following disassembly

0000000000400440 <main>:
400440: 48 83 ec 08 sub $0x8,%rsp
400444: bf c4 05 40 00 mov $0x4005c4,%edi
400449: e8 c2 ff ff ff callq 400410 <puts@plt>
40044e: 31 c0 xor %eax,%eax
400450: 48 83 c4 08 add $0x8,%rsp
400454: c3 retq

from the following program:

int main(void)
{
printf("hello, world\n");
return 0;
}




>
>> Frankly, the result of this patch seems extremely unreadable code.
>
> Do you care for more complete error detection and corresponding exception handling
> in this source file?


I like the code as is.

Such error checks and magic numbers are messy.



--
Best Regards
Masahiro Yamada