Liste des Groupes | Revenir à cl c |
On 06/11/2024 14:50, David Brown wrote:You mean it is something you don't understand? Think of this as an opportunity to learn something new.On 05/11/2024 23:48, Bart wrote:On 05/11/2024 13:29, David Brown wrote:int small_int_sqrt(int x) {
if (x == 0) return 0;
if (x < 4) return 1;
if (x < 9) return 2;
if (x < 16) return 3;
unreachable();
}"unreachable()" is a C23 standardisation of a feature found in most high-end compilers. For gcc and clang, there is __builtin_unreachable(), and MSVC has its version.So it's a kludge.
Cool, I can create one of those too:You are missing the point - that is shown clearly by the "int.min".
func smallsqrt(int x)int =
if
elsif x=0 then 0
elsif x<4 then 1
elsif x<9 then 2
elsif x<16 then 3
dummyelse int.min
fi
end
'dummyelse' is a special version of 'else' that tells the compiler that control will (should) never arrive there. ATM it does nothing but inform the reader of that and to remind the author. But later stages of the compiler can choose not to generate code for it, or to generate error-reporting code.
BTW your example lets through negative values; I haven't fixed that.)Again, you are missing the point.
This is all a large and complex subject. But it's not really the point of the discussion.You haven't followed the discussion or considered it to have a point. To you, the "point" of /all/ discussions here is that you hate everything about C, think that everyone else loves everything about C, and see it as your job to prove them "wrong".
Les messages affichés proviennent d'usenet.