Click here to Skip to main content
Licence 
First Posted 8 Mar 2003
Views 28,678
Bookmarked 11 times

Using UNION when porting a Fortran EQUIVALENCE code

By | 8 Mar 2003 | Article
Using UNION when porting a Fortran EQUIVALENCE code.

Introduction

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
{
 struct
 {
  double a;
  double b;
  double c;
 } s;
 double x[3];
} mix; 
//=======================
void main()
{
    mix.s.a=12.1;
    mix.s.b=12.2;
    mix.s.c=12.3; 
 for (int i=0;i<3;i++) cout<<mix.x[i]<<endl;
}
//======================

I wish to give credit to this article.

License

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

Member

Retired EE

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralFor those with the need... PinmemberNitron14:25 11 Mar '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120517.1 | Last Updated 9 Mar 2003
Article Copyright 2003 by Gabor Kalman
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid