Click here to Skip to main content
15,077,641 members
Articles / Programming Languages / C++
Posted 8 Mar 2003


12 bookmarked

Using UNION when porting a Fortran EQUIVALENCE code

Rate me:
Please Sign up or sign in to vote.
3.67/5 (8 votes)
8 Mar 2003
Using UNION when porting a Fortran EQUIVALENCE code.


For those of us who need to port from Fortran:

In C++ there is no equivalent structure to Fortran's EQUIVALENCE. (No pun intended!)

After doing some searching, I could not find an appropriate code, so I am suggesting the following "work-around" using the UNION structure.

The basic idea is that the same portion of the memory is accessed by different data. (Variables or data types).

#include <iostream.h> 
union mix_it
  double a;
  double b;
  double c;
 } s;
 double x[3];
} mix; 
void main()
 for (int i=0;i<3;i++) cout<<mix.x[i]<<endl;

I wish to give credit to this article.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Gabor Kalman
Web Developer
United States United States
Retired EE

Comments and Discussions

Generalvery good trick Pin
Southmountain20-Oct-20 5:34
MemberSouthmountain20-Oct-20 5:34 
GeneralFor those with the need... Pin
Nitron11-Mar-03 14:25
MemberNitron11-Mar-03 14:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.