tripack45 / VE280-Notes

Recitation class lecture notes for VE280
GNU General Public License v3.0
17 stars 2 forks source link

[Problems] About Week 5 #2

Closed tc-imba closed 4 years ago

tc-imba commented 7 years ago

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

-O0 Reduce compilation time and make debugging produce the expected results. This is the default.

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 printing 225 on my computer.

tc-imba commented 7 years ago

Just too boring tonight ...

Airtnp commented 7 years ago

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).

tripack45 commented 7 years ago

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.

zzhou612 commented 6 years ago

羡慕强者之间的交流

tripack45 commented 4 years ago

Closing this 3yo issue. Thanks everyone!