Pascal does not consider the result type when determining the result type of an expression. Also as y.ivanov wrote, expressions are evaluated left-to-right and its completely legitimate for the compiler not to optimize this.
Лично моё мнение - это не правильно. Но возможно ни кто и не занимался данным вопросом. Если это интересно для развития FPC, то я могу заняться созданием анализатора кода и оптимизацией кода паскаля (не ассемблерного, а именно паскаля). Протестируете, посмотрите как работает и есть ли от него смысл.
Я ни в коем случае не говорю, что FPC не оптимизирован. Я даже могу сказать, что достаточная часть компилятора обрабатывает код лучше меня.
Но я зачастую вижу что происходит в конечном коде и понимаю, где можно сделать код быстрее и (или) меньше. Я ставлю подсказки компилятору и компилятор успешно пользуется этими подсказками.
Но это ручная работа!!! А это не очень хорошо.
Я всё равно занимаюсь своими разработками и попутно могу заниматься анализом кода. По полученным данным составлю анализатор кода. Впоследствии такого анализа код на паскале вероятнее всего вырастет, но конечный компилируемый код с большой вероятностью уменьшится и будет работать быстрее.
Интересно вам моё предложение?
Yandex translate:
Personally, my opinion is wrong. But perhaps no one has dealt with this issue. If this is interesting for the development of FPC, then I can create a code analyzer and optimize Pascal's code (not assembler, namely pascal). Test it, see how it works and whether it makes sense.
I am by no means saying that FPC is not optimized. I can even say that a sufficient part of the compiler handles the code better than me.
But I often see what happens in the final code and understand where it is possible to make the code faster and (or) smaller. I put hints to the compiler and the compiler successfully uses these hints.
But it's handmade!!! And this is not very good.
I'm still doing my own development and I can do code analysis along the way. Based on the received data, I will compile a code analyzer. After such an analysis, the pascal code is likely to grow, but the final compiled code is likely to decrease and run faster.
Are you interested in my offer?