Liste des Groupes | Revenir à cl c |
On 25/04/2025 19:38, Thiago Adams wrote:This is easy for constant.Does anyone know of any platform where integer division by zero returns a number, or in other words, where it's not treated as an error? I'm asking because division by zero is undefined behaviour, but I think division by a constant zero should be a constraint instead.Some processors might give a specific value for their integer division instructions for divide by 0 - or they might support masking of relevant traps, exceptions or other fault mechanisms. Software should probably not rely on division by 0 behaviour, even if it is in non-portable code.
>
But most processors that are too small to have a fault, trap or exception system are also too small to have division instructions. There are exceptions, of course.
Division by a constant 0 is not a constraint in C because that would require compilers to detect division by zero.
are free to detect it anyway, and issue a warning. Note that compilers should probably not consider it a fatal error in the code (i.e., one that stops the compilation) unless the compiler can be sure that the code in question is not executed. There is no problem having undefined behaviour in the code until you try to execute that code path.Since 1/0 is not a constant, then if 1/0 were a constrain, the programmer could use a variable instead.
Les messages affichés proviennent d'usenet.