What are the historical reasons C languages have pre-increments and post-increments?

后端 未结 6 974
广开言路
广开言路 2021-02-08 12:32

(Note: I am not asking about the definitions of pre-increment vs. post-increment, or how they are used in C/C++. Therefore, I do not think this is a duplicate question.)

6条回答
  •  借酒劲吻你
    2021-02-08 13:31

    To get an answer that goes beyond speculation, most probably you have to ask Dennis Ritchie et al personally.

    Adding to the answer already given, I'd like to add two possible reasons I came up with:

    • lazyness / conserving space:

      you might be able to save a few keystrokes / bytes in the input file using the appropriate version in constructs like while(--i) vs. while(i--). (take a look at pmg s answer to see, why both make a difference, if you didn't see it in the first run)

    • esthetics

      For reasons of symmetry having just one version either pre- or postincrement / decrement might feel like missing something.

    EDIT: added sparing a few bytes in the input file in the speculation section providing, now providing a pretty nice "historic" reason as well.

    Anyways the main point in putting together the list was giving examples of possible explanations not being too historic, but still holding today.

    Of course I am not sure, but I think asking for a "historic" reason other than personal taste is starting from a presumtion not neccesarily true.

提交回复
热议问题