Const Expression in c++

Apr 11, 2022

NOTE: this is just copy-pasting from stackoverflow and some textbooks, see references below.

  • const: meaning roughly “I promise not to change this value.” This is used primarily to specify interfaces so that data can be passed to functions using pointers and references without fear of it being modified. The compiler enforces the promise made by const. The value of a const can be calculated at runtime.

  • constexpr: meaning roughly “to be evaluated at compile time.” This is used primarily to specify constants, to allow placement of data in read-only memory (where it is unlikely to be corrupted), and for performance. The value of a constexpr must be calculated by the compiler.

You should read from right to left. This is refered to as clockwise/spiral rule

  • int * pointer to int
  • int const * == const int * pointer to const int
  • int * const const pointer to int
  • int const * const == const * const const pointer to const int

and …

  • int ** pointer to pointer to int
  • int ** const const pointer to pointer to int
  • int * const * pointer to const pointer to int
  • int const ** pointer to pointer to const int
  • int * const * const const pointer to const pointer to int.
Read more ...

Deconstruct

Mar 10, 2022

过度的、纯粹的解构会脱离人的本能理解,以至于解构本身需要与一个解释捆绑在一起才能具有意义,于是,解构反而成为了一个新的构筑。

现代艺术从经验主义和形式主义的束缚(比如:你必须画得像,做得真),转向了一种新的束缚:符号是摆脱了细节的抽象,但他必须由环境,语言,历史,社会赋予意义。

Read more ...

Shells

Nov 29, 2021

在Lidl买了一盒海虹,放进锅里,一点点水,关盖子焖五六分钟就可以吃了,什么都不用加。

生活小常识:煮之前开着壳的和煮之后闭着壳的不要吃。

Read more ...