Click here to Skip to main content
14,149,668 members
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 8 Mar 2003

Using UNION when porting a Fortran EQUIVALENCE code

, 8 Mar 2003
Rate this:
Please Sign up or sign in to vote.
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

You may also be interested in...


Comments and Discussions

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190518.1 | Last Updated 9 Mar 2003
Article Copyright 2003 by Gabor Kalman
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid