Fortran How do i 'relabel' variables (in fortran)

  • Thread starter Thread starter tothetop
  • Start date Start date
  • Tags Tags
    Fortran Variables
AI Thread Summary
In C++, using a local constant pointer like "gc" to reference a global variable such as "GauntCoefficients" enhances code readability and keeps the global namespace clean. This approach allows the compiler to optimize by potentially eliminating the pointer. In Fortran 90 and later, similar functionality can be achieved using pointers, although they come with more restrictions compared to C/C++. In Fortran, one can declare "GauntCoefficients" as a target variable and then create a pointer "gc" that references it, allowing for cleaner code while maintaining the integrity of the global variable.
tothetop
Messages
2
Reaction score
0
Suppose I have a global variable like "GauntCoefficients".. and I want to use it in a formula in the next block of code. In C++, I might do something like this to make the code more readable:

const int* gc = GauntCoefficients;
(then write some nasty formula with "gc" rather than "GauntCoefficients" everywhere)

Since "gc" is declared here as a constant, the compiler should just delete it (I think). And since "gc" id declared locally.. it doesn't pollute the namespace.

Can I do something like that in Fortran?
 
Technology news on Phys.org
Hey
In Fortran 90 and newer pointers are possible to use. But they are more restrictive than in e.g. C/C++.
You can therefore do something like this:
Code:
integer, target::GauntCoefficients
integer, pointer::gc
gc=>GauntCoefficients

I hope this helps.
 
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 had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
25
Views
3K
Replies
8
Views
4K
Replies
3
Views
2K
Replies
3
Views
2K
Replies
3
Views
3K
Replies
59
Views
11K
Replies
16
Views
2K
Replies
3
Views
1K
Replies
13
Views
1K
Back
Top