MIN and MAX in C

后端 未结 14 1541
攒了一身酷
攒了一身酷 2020-11-22 13:32

Where are MIN and MAX defined in C, if at all?

What is the best way to implement these, as generically and type safely as possible? (Compil

14条回答
  •  温柔的废话
    2020-11-22 14:17

    I know the guy said "C"... But if you have the chance, use a C++ template:

    template T min(T a, T b) { return a < b ? a : b; }
    

    Type safe, and no problems with the ++ mentioned in other comments.

提交回复
热议问题