Fortran Can equations be used in Fortran array declarations with parameters?

  • Thread starter Thread starter Matterwave
  • Start date Start date
  • Tags Tags
    Array Fortran
AI Thread Summary
In the discussion, the main focus is on the use of equations in array declarations in Fortran. It clarifies that array bounds must be INTEGER constants, and while constants declared with the PARAMETER statement are acceptable, they must precede the array declaration. The conversation highlights that if 'y' is a parameter, using it in an array declaration like "real, dimension(2*y)::x" is legitimate. The distinction between assignment and equality testing is also emphasized, noting that Fortran uses different symbols for these operations. The clarification that parameters have values known at compile time, allowing the compiler to allocate memory correctly, is a key point. Overall, the discussion confirms that using parameters in array dimensions is valid in Fortran programming.
Matterwave
Science Advisor
Homework Helper
Gold Member
Messages
3,971
Reaction score
329
Hi, I'm just wondering real quick, are equations allowed in array declarations? For example:

int :: y=2
int, dimension(2*y):: x

?
 
Technology news on Phys.org
I don't think the equation you have would be permitted, as the array bounds must be INTEGER constants. However, constants declared with the PARAMETER statement are OK for array declarations, as long as the PARAMETER statement precedes the array declaration.

http://star-www.st-and.ac.uk/~spd3/Teaching/AS3013/lectures/AS3013_lecture5.pdf
 
So even if y were a parameter, probably I still can't do that?

EDIT: I looked at a later part of the lecture and he had something like what I have except y is a parameter. So I think I'm doing OK. Thanks. :)
 
The whole point of a parameter in Fortran is that the parameter's value is known at compile time, so the compiler knows how much memory to allocate for the array. For a variable (not a parameter), the variable gets its value at run time, I believe.

Minor point. A statement such as y = 2 is an assignment, or in this case an initialization, not an equation. It does not state that y and 2 are equal. Instead, it stores the constant value 2 in the location that is named y.

Most programming languages make distinctions between assignment and testing for equality by using different symbols. For example, Fortran uses .EQ. to test for equality, and uses = for assignment. Languages based on C, such as C++, C#, Java, and others, use == to test for equality and = for assignment. Newer versions of Fortran now support the C-style notation, in addition to the older .EQ., .LT., GT., and other spelled-out relational operators.
 
Yes, I forgot to include that y is a parameter, and my language is lazy because I'm not a programmer really. Sorry for the confusion. :P

I just wanted to make sure that the statement

real, dimension(2*y)::x

is legitimate if y is a parameter, and Steamking's link had something just like that in it.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top