__attribute__((constructor)) call order confusion

前端 未结 4 1029
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 02:55

The answer here demonstrates that __attribute__((constructor)) is not called after static initialization, it is called in the declaration order.

Then, w

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 03:23

    the biggest advantage of attribute((constructor))__ is the priority associated with each block and specifically helps your case.

    You have two block of codes which have data hazard (one set should be executed first). This cannot be achieved by single static block. Using one static block and one attribute((constructor))__ will not solve your problem because of confusion regarding the order.

    The best way to deal with the problem is to have two attribute((constructor))__ with two different priorities. Move your existing static initialization block to higher priority (0) and the other code block to lower priority.

提交回复
热议问题