Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:06:42+00:00 2026-06-04T04:06:42+00:00

program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; var ints: array[1..2] of Integer =

  • 0

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

var
  ints: array[1..2] of Integer = (0,0);
  i   : Integer;

begin
  ints[5] := 10;    // doesn't compile
  i := 5;
  ints[i] := 10;    // Seems to works
  Writeln(ints[i]); // and even display the value
  Readln;
end.

I have set a bound to the array ints.

Usually, I check the Low(ints) and High(ints) before trying to set a value to a bounded array…
But as I was looking to another piece of code, I notice that I can use index outside from the boundary and that it doesn’t raise any exception…

I’d like to know why it works and what are the consequence?
(for example, if this part of memory is not reserved and I can corrupt it, …)

I have searched for others questions but haven’t found the good one… if it’s exist, do not hesitate to put the link and close this one, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:06:43+00:00Added an answer on June 4, 2026 at 4:06 am

    Because the compiler does not perform data flow analysis. In order for the compiler to reject this code it would need to analysis your code and be sure that i was out of bounds and the compiler simply does not do so. To do so for even moderately more complex examples would require a very significant effort from the compiler developers.

    Since this code will fail with a runtime error if you switch range checking on, I personally feel that there is little to be gained by adding such data flow analysis to the compiler. If you are not running with range checking enabled, then you really should be.

    One of the numerous benefits about getting the compiler to perform range checking is that in many cases you can expunge your range checking code. This will make your code much clearer. However, you can only do this when you are in full control of the index and can analyse the code statically. If the index comes from user input, then clearly you need to provide protection against abuse.

    You ask what are the consequences of running this code without range checking. Well, the behaviour is not defined and really anything could happen. Worst case scenario is that the program always works for you but fails in a critical way for your most important clients.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just tried program Project1; {$APPTYPE CONSOLE} uses SysUtils; begin {$IFDEF CONSOLE} beep; {$ENDIF}
I have problems in a following code: program Project4; {$APPTYPE CONSOLE} uses SysUtils, RTTI;
I don't understand why the following small console application does not compile: program Project1;
Is there a way to make something like this work? program Project1; {$APPTYPE CONSOLE}
Despite being a Project Euler program, the following code doesn't actually concern it much.
I have a solution consisting of two projects: Project1 containing a single file program.cpp
How could I compile a .cs program that references a COM DLL from the
So I wrote a project-management program for a small business using Microsoft Access 2007.
I delete my java program from java project in eclipse. The extension was .java
I have a school project to program multilayer perceptron that classify data into three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.