Liste des Groupes | Revenir à cl c |
On 06/11/2024 14:50, David Brown wrote:
It looks like it needs 'else' here. If I put that in, then F(0) returns either 0 or 1, so it returns garbage, whether or not 'unreachable' is used in the branch.C gets it right here. There is no need for a return type when there is no returnThere is no return for only half the function! A function with a return type is a function that CAN return. If it can't ever return, then make it a procedure.
Take this function where N can never be zero; is this the right way to write it in C:
int F(int N) {
if (N==0) unreachable();
return abc/N; // abc is a global with value 100
}
If doesn't look right. If I compile it with gcc (using __builtin_unreachable), and call F(0), then it crashes. So it doesn't do much does it?!
Les messages affichés proviennent d'usenet.