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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:34:54+00:00 2026-05-21T10:34:54+00:00

When compiled with either GNU Fortran (v4.4.3) or Sun Studio F95 (v8.3) and no

  • 0

When compiled with either GNU Fortran (v4.4.3) or Sun Studio F95 (v8.3) and no array bounds checking the following program runs without error. However, when array bounds checking is switched on (gfortran -fbounds-check and f95 -C, respectively) the GNU compiled executable runs again without error, whereas the Sun Studio compiled executable gives the run-time error,

 ******  FORTRAN RUN-TIME SYSTEM  ******
Subscript out of range. Location:  line 44 column 20 of 'nosize.f90'
Subscript number 2 has value 1 in array 't$27'

That’s an error in the call to sub2(), which uses an automatic array dummy argument for x. The sub1() calls run fine with either compiler and any flags.

To my knowledge this program is “legal”, in that a zero sized array may be referenced like a non-zero sized array, and there is no explicit indexing of the zero length dimension of x. But is there some zero sized array slicing or automatic array subtlety that I’m missing here? And should I expect array bounds checking to behave the same across different compilers, or should I consider it a vendor-specific extension?

MODULE subs
  IMPLICIT NONE
CONTAINS    
  SUBROUTINE sub1(x)
    IMPLICIT NONE
    REAL :: x(:,:)
    PRINT*,'------------------------------------'
    PRINT*,SHAPE(x)
    PRINT*,SIZE(x)
  END SUBROUTINE sub1

  SUBROUTINE sub2(n1,n3,x)
    IMPLICIT NONE
    INTEGER,INTENT(in) :: n1, n3
    REAL :: x(n1,n3)
    PRINT*,'------------------------------------'
    PRINT*,SHAPE(x)
    PRINT*,SIZE(x)
  END SUBROUTINE sub2
END MODULE subs


PROGRAM nosize
  USE subs
  IMPLICIT NONE    
  INTEGER :: n1 = 2, n2 = 2, n3 = 0
  REAL,ALLOCATABLE :: x(:,:,:)

  ALLOCATE(x(n1,n2,n3))
  x(:,:,:) = -99.9

  PRINT*,'ALLOCATED? ',ALLOCATED(x)
  PRINT*,'SHAPE =',SHAPE(x)
  PRINT*,'SIZE  =',SIZE(x)
  PRINT*,'X     =',x

  CALL sub1(x(:,1,:))
  CALL sub2(n1,n3,x(:,1,:))

END PROGRAM nosize
  • 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-05-21T10:34:55+00:00Added an answer on May 21, 2026 at 10:34 am

    It doesn’t give any problems with intel’s fortran compiler with -check bounds; and IBM’s xlf, which in my experience is extremely strict, also didn’t complain with -qcheck.

    But more broadly, yes, there’s no standard about what bounds checking should or shouldn’t do. I can certainly see why some compilers would flag an assignment to a zero-length array as being bad/wrong/weird; it is a strange corner-case.

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

Sidebar

Related Questions

I compiled the following code: // Triangle.cpp // Our first OpenGL program that will
I compiled 2 different binaries on the same GNU/Linux server using g++ version 4.2.3.
Can anyone recommend either: an ARM disassembler that runs in either Windows or MacOS
I tried to run my program compiled with Apple GCC 3.2.1 (forced 32-bit mode,
I opened up my compiled Hello World Obj-C application in a text editor and,
How do I lock compiled Java classes to prevent decompilation? I know this must
I have a compiled swf file and a I can't edit it , but
Can iPhone applications compiled against 2.1 be successfully installed via iTunes on a 2.0
Can a WinForms app compiled for Any CPU be configured to run as x86
I've compiled a java project into a Jar file, and am having issues running

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.