Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It used to, but it doesn't anymore, presuming you use a reasonably recent compiler. If you enable optimizations the assembly for that snippet and the default constructor are identical, I last checked on some GCC 5 flavor, but I think it was like this all the way back in GCC 3 something.

Compilers can do some pretty fancy things with literals because they know they optimize constants known at compile time.



I just started using GCC 5.4 - I'll have to check again. Last I checked was around 4.8, and it was still generating sub optimal code with the empty literal.


Enabling the optimizations is important too. If you leave it on the defaults it does a very direct translation to machine code.

GCC 7 is available for use now.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: