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

  • Home
  • SEARCH
  • 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 8392813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:37:06+00:00 2026-06-09T19:37:06+00:00

I have the following program at hand program foo type bar real, dimension(2) ::

  • 0

I have the following program at hand

program foo
  type bar
    real, dimension(2) :: vector
  end type
  type(bar), dimension(3) :: bararray
  call doSomething(bararray%vector)
end program

subroutine doSomething(v)
  real, dimension(3,2), intent(inout) :: v
  ...
end subroutine

Now this gives me a compilation error.

Error: Two or more part references with nonzero rank must not be specified at (1)

If I change the call to

call doSomething((/bararray%vector(1), bararray%vector(2)/))

everything works out nicely. The thing is that this just seems a bit cumbersome, so the question is, is there any other way to write the argument for the subroutine?

Thanks in advance.

  • 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-09T19:37:07+00:00Added an answer on June 9, 2026 at 7:37 pm

    The error arises because there is a constraint (in F2008 the syntax rule is C618) in the language that only one part in a structure component (or similar multi-part reference) may have non-zero rank. Your reference bararray%vector to the structure component has two parts with non-zero rank – the component vector and the variable bararray.

    (In the “change the call” approach the references to the component vector have a subscript that gives that part an overall rank of zero, hence bararray%vector(1) is accepted.)

    There is a significant latent problem with the “change the call” approach.

    The dummy argument in the subroutine is INTENT(INOUT). That requires the actual argument to be definable (a variable that can actually be “varied”).

    In your “change the call” approach the actual argument associated with that dummy argument is an expression – an array constructor. Expressions are not definable – the result of evaluating them is a value and not something that can be “defined” – i.e. you can’t sanely say 2 + 2 = 6.

    Presumably in the real code the doSomething subroutine is an external procedure, so your compiler has not diagnosed this. If doSomething had an explicit interface (because it was in a module, perhaps) then I would expect the compiler to report an error.

    Others have suggested the approach of re-marshalling your data prior to the call (copy data into an array variable of the appropriate size, call the procedure, copy the data out). Rewriting the interface of the subroutine to take objects of type bar (with the definition of the type moved to a module) is obviously another possibility. Derived types are not only a convenient way of storing data, they are often a convenient way of working with data.

    I would be very wary of approaches that attempted to trick the processor into accepting what you “know” to be the layout of the hypothetical array bararray%vector in memory. The layout of types and arrays can change from processor to processor, plus as processor error checking improves that sort of trick may result in later diagnostics. Vendor supplied libraries can get away with that sort of trick, but not us mere programming mortals.

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

Sidebar

Related Questions

I have following simple program: import std.stdio; int main(string[] argv) { writeln(Hello, world!); return
I have the following program. I wonder why it outputs -4 on the following
I have the following program flow: User fills in form My app generates a
I have a following program but for some reason it is throwing an error
I have the following program to open lot's of sockets, and hold them open
I have the following program to browse all virtual directories and their sub directories
Hi I have the following program. When I compile on the terminal gcc main.c
I have the following c program which launches a Gtk Program on ubuntu: #include
I have tried the following program for writing the contents into Spreadsheet. I downloaded
I have the following MonoTouch program: using System.Drawing; using MonoTouch.Foundation; using MonoTouch.UIKit; using System;

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.