What is the most efficient way to represent small values in a struct?

前端 未结 15 842
星月不相逢
星月不相逢 2021-02-01 02:15

Often I find myself having to represent a structure that consists of very small values. For example, Foo has 4 values, a, b, c, d that, range from

15条回答
  •  孤街浪徒
    2021-02-01 03:02

    Code it with ints

    treat the fields as ints.

    blah.x in all your code, except the declarion will be all you will be doing. Integral promotion will take care of most cases.

    When you are all done, have 3 equivalant include files: an include file using ints, one using char and one using bitfields.

    And then profile. Don't worry about it at this stage, because its premature optimization, and nothing but your chosen include file will change.

提交回复
热议问题