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 7720901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:47:16+00:00 2026-06-01T03:47:16+00:00

I have a program that assigns an array beyond it’s bounds, and I was

  • 0

I have a program that assigns an array beyond it’s bounds, and I was expecting a run-time error to be thrown. Yet no error is raised at all and the program proceeds to write into undeclared memory. Is there some compiler option to guard against this? With the memory dump shown it is clear this overreach of bounds is real. Is there a way to declare variables or argument specs to catch this? Obviously this is a clear case, but when tasked to maintain thousands of lines of F77 derived code it is not always clear (to me) if this might be happening.

PROGRAM TEST_CODE
IMPLICIT NONE

INTEGER*4 :: R(5)           ! Array of 5

    CALL R_TEST(R, 10)

END PROGRAM

SUBROUTINE R_TEST(R, J)
IMPLICIT NONE

INTEGER*4, INTENT(INOUT) :: R(1)    ! Dummy is array of 1
INTEGER*4, INTENT(IN) :: J
INTEGER*4 :: K

DO K=J-5,J+5            ! K=5..15
    R(K) = K            ! No Runtime Error
END DO

END SUBROUTINE

Compiler is Intel Fortran 2011 XE, and yes I am using the byte spec INTEGER*4 because I know what I get with it.

Here are the compiler options for runtime checking.
Compiler Options

Memory of <code>R</code> variable

  • 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-01T03:47:17+00:00Added an answer on June 1, 2026 at 3:47 am

    The intel compiler does a very good job on bounds checking for the pointer and allocatable arrays. If you slightly modify your code (below) and compile with something like:

    $ ifort -O0 -debug -traceback -check -ftrapuv TEST_CODE.f90

    you will get a run time error. But for assumed size arrays the intel compiler cannot check the bounds. Especially for F77 codes with implicit typing and so on it won’t be easy to find memory leaks. Another tiny thing, in Fortran your program has to do something meaningful; otherwise the compiler will omit your code because it simply does nothing! That’s why I added a print in the end.

    There is a small problem with R(:) thing is that the compiler cannot assume that it is contiguous in the memory; hence it cannot make some compiler optimization. It would then be better to use allocatable arrays or use the contiguous attribute (F2008 standard).

    PROGRAM TEST_CODE
    IMPLICIT NONE
    
    INTEGER*4 :: R(5)           ! Array of 5
    
        CALL R_TEST(R, 10)
        print *,R
    
    END PROGRAM
    
    SUBROUTINE R_TEST(R, J)
    IMPLICIT NONE
    
    INTEGER*4, INTENT(INOUT) :: R(:)    ! Dummy is array of 1
    INTEGER*4, INTENT(IN) :: J
    INTEGER*4 :: K
    
    DO K=J-5,J+5            ! K=5..15
        R(K) = K            ! No Runtime Error
    END DO
    
    END SUBROUTINE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following program that assigns dictionary keys to an array ( addr[]
I have a program that spits out both standard error and standard out, and
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that spits out an Excel workbook in Excel 2003 XML
I have a program that monitors debug messages and I have tried using a
I have a program that will calculate the minimal area taken by fitting rectangles
I have a program that runs osql.exe from microsoft sql server tools directory and

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.