How to combine static_assert with sizeof and stringify?

后端 未结 4 1949
忘掉有多难
忘掉有多难 2020-12-30 01:55

Memory usage is quite critical in my application. Therefore I have specific asserts that check for the memory size at compile time and give a static_assert if the size is d

4条回答
  •  遥遥无期
    2020-12-30 02:56

    As you discovered, the problem is here (also see this very similar question) :

    #define CHECKMEM(mytype, size)  #sizeof(mytype)
    

    It is not possible to do, because the stringification is done by the preprocessor, and sizeof is evaluated during the compilation.

提交回复
热议问题