What type for subtracting 2 size_t's?

后端 未结 4 1541
花落未央
花落未央 2020-12-30 00:46

Which type in C should be used to represent the difference between two objects\' sizes?

As size_t is unsigned, something like

size_t dif         


        
4条回答
  •  时光说笑
    2020-12-30 01:40

    You could do this:

    size_t diff = std::abs(static_cast  (sizeof (small_struct) - sizeof (big_struct)));
    

提交回复
热议问题