Closed tc-imba closed 4 years ago
Just too boring tonight ...
It's possible that all operations on x is based on *ax, may be you can try function with more parameters and more calculation.
However, UB's haviour is meaningless. That's just a call stack introduction based on common ABI (Itanium/MSVC).
As I commented on previous slides all puzzles includes undefined behaviors. The point is to see how calling stacks can be used to provide an explanation if DO witness such behavior. In class I said "The puzzles don't necessarily work on your platform. In fact I don't expect them to work on most of your system, and I don't expect to work after I reboot my system".
VLAs are optional indeed. I guess It's better to take "optional" as "not supported". After all every feature tha is not required by the standard are "optional", for example you can say a garbage collector for c++ is "optional", and it's so "optional" that non of the traditional compilers support it.
羡慕强者之间的交流
Closing this 3yo issue. Thanks everyone!
There're some problems about RC Week 5.
First, in Puzzle 0, about VLA
Actually Variable Length Arrays is a feature in ISO-C99 , and is fully supported by GCC since GCC 0.9 (Status of C99 features in GCC). Though in ISO-C11, it is relegated to a conditional feature which implementations are not required to support. In g++, you may use it after enabling a plugin.
I know that using VLA is not recommended due to various issues, but really works by the test on ideone. So I think you should correct
both C++ and C choose not to support this language feature (above code won't compile)
Second, about Puzzle 2
on GCC Documentation about optimization, I found that
So I can understand why enabling O1 would make the function work according to your explanations. However, strange things happened in my gcc. No matter how I try the optimization modes (O0/O1/Og/...) or add a varible
y
, or try the debug mode, the program keeps printing225
on my computer.