12/30/2023 0 Comments Integer faqt type![]() Which isn’t very useful in calculating factorials. Now in Ada, integers generally are in the range: –(2^31) → (2^31)-1 But it overflowed in a nice way, and just exited the program, as opposed to crashing. The program overflowed because the number being calculate was too large to be stored as an integer. Raised CONSTRAINT_ERROR : factorial.adb:13 overflow check failed For example, if we compile and run this program, entering 20 for the number of factorials we wish to calculate, we get the following output: n! ? Now the interesting things about Ada is its ability to stop certain things happening, that languages would just basically ignore. This essentially stops loop indexes being used for something they should be used for. Warning: declaration hides "i" declared at line 5 Warning: for loop implicitly declares loop variable If you accidentally declare the loop index outside the loop (say on line 5 of the program), you will get a compiler warning of the following form: warning: variable "i" is never vad and never assigned Although in modern versions of C you can choose to declare the loop index within the loop, in Ada the loop itself takes care of that. The last point is particularly worth noting. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |