Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Quick Question: Array Boundaries.

cr362
Beginner
1,064 Views

Dear All,

Why is it that if I declare an array and then reference outside the bounds of the array, no error comes up?

e.g. If I do

real example(100,100)

example(400,400)=1.5

My compiler seems to think that this is ok? I can then use the value stored in example (400,400) in further calculations.

I just don't understand why my compiler doesn't flag this up?? Is there a way to make it flag it up?

I'm using Intel fortran compiler on a linux server.

Cheers.

0 Kudos
3 Replies
Kevin_D_Intel
Employee
1,064 Views

Try adding: -check bounds

[cpp]program sample
real example(100,100)
example(400,400)=1.5
end[/cpp]

$ ifort -V -check bounds example.f90

Intel Fortran Compiler for applications running on IA-32, Version 10.1 Build 20080801 Package ID: l_fc_p_10.1.018

Copyright (C) 1985-2008 Intel Corporation. All rights reserved.

Intel Fortran 10.1-2051

fortcom: Error: example.f90, line 3: Subscript #2 of the array EXAMPLE has value 400 which is greater than the upper bound of 100

example(400,400)=1.5

^

fortcom: Error: example.f90, line 3: Subscript #1 of the array EXAMPLE has value 400 which is greater than the upper bound of 100

example(400,400)=1.5

^

compilation aborted for example.f90 (code 1)

0 Kudos
cr362
Beginner
1,064 Views

Cheers, and sorry for the newbie question!

Try adding: -check bounds

[cpp]program sample
real example(100,100)
example(400,400)=1.5
end[/cpp]

$ ifort -V -check bounds example.f90

Intel Fortran Compiler for applications running on IA-32, Version 10.1 Build 20080801 Package ID: l_fc_p_10.1.018

Copyright (C) 1985-2008 Intel Corporation. All rights reserved.

Intel Fortran 10.1-2051

fortcom: Error: example.f90, line 3: Subscript #2 of the array EXAMPLE has value 400 which is greater than the upper bound of 100

example(400,400)=1.5

^

fortcom: Error: example.f90, line 3: Subscript #1 of the array EXAMPLE has value 400 which is greater than the upper bound of 100

example(400,400)=1.5

^

compilation aborted for example.f90 (code 1)

0 Kudos
Kevin_D_Intel
Employee
1,064 Views

No apology is necessary. We welcome all questions.

Also, Welcome to the Intel Software Network User Forums!

0 Kudos
Reply