A nifty site to see what a compiler does to C++ code
a very intermittent unit test failure this week, I noticed an anomaly in our
code.This test is written in c++ and
had an extra semicolon in it:
We had a test that
did something like this:
Worksheet wb =
Notice that extra ;
in the middle?Since the test
intermittently fails, I was looking for anything unexpected in the code.This is unexpected, but I also needed to know
if it was important.
Matt Godbolt created
a terrific site that lets you put in C++ code and see what output various
compilers produce.The site is herehttps://gcc.godbolt.org/
You can choose
different compilers and I just took a look at gcc 6.3 to see if it would ignore
an extra ;.
Here's my test code:
And here is the
movDWORD PTR [rbp-4], 1
I get the same
output with or without the extra semicolon. This is great since I would expect
the compiler to get rid of blank commands like this.Since the compiler does indeed ignore this
typo in the code, I can move on to other avenues of investigation.
Give this site a
whirl.You can choose several different
compilers and chip options, pass parameters in and so on.Thanks Matt!
Questions, comments, concerns and criticisms always welcome,