Consider a class like:
struct mystruct { constexpr operator char() {return x;} signed char x; };
and operation like:
mystruct m; mx = /* something at runtime */ int i = 3 * m + 45ULL * m;
Can compilers skip the temporary conversion to char and convert directly m to the required type in the expression 3 * m + 45ULL * m ?
char
m
3 * m + 45ULL * m
It seems that GCC version 5.3.0 can optimize the translation function call, while Clang 3.7 is not so smart.
For this piece of code:
struct mystruct { constexpr operator char() const {return x;} signed char x; } m; void func(const int num) { mx = num*2; int i = 3 * m + 45ULL * m; }
you can check the compiled assembly and compare them:
Clang with cast vs Clang with a direct link to the field
Gcc with cast vs Gcc with direct link to the field
Although in a slightly different situation, Clang does manage to optimize the translation function call.
Source: https://habr.com/ru/post/1238612/More articles:setInterval with infinity - javascriptKubernetes Endpoint Access Issues - dockerbootstrap-input-group - htmlAjax will not allow the correct css link style - jqueryGetting Transformation Exception When Building a Project - androidCombining multiple user taxonomy of users in a single URL - wordpressAngularjs filter doesn't work when undefined property - javascriptDynamic search function to show / hide divs - javascript. The current CSS link style only works on the first page and does not move on to another - htmlHow to change url parameter as directory in Yii2? - urlAll Articles