- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
....
int *n1, b;
float **n2, **n3;
n1= new float ;
n2= new float *;
n3= new float *;
for(int j=0;j<b;j++)
{
ge>>n1
n2
n3
for(int i=0;i<n
{
ge>>n2
}
}
...
I understand the code, it is the indirection and multiple indirection and allocation, right ? I try to translate these codes into Fortran. Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
emreka82 wrote:The above program is in error. "n1= new float ;" is allocating an array of floats and assigning its pointer to the int* n1. Jim DempseyHi,
....
int *n1, b;
float **n2, **n3;
n1= new float ;
n2= new float *;
n3= new float *;
for(int j=0;j<b;j++)
{
ge>>n1
; n2
= new float [n1 ]; n3
= new float [n1 ]; for(int i=0;i<n
;i++) {
ge>>n2
>>n3 ; }
}
...
I understand the code, it is the indirection and multiple indirection and allocation, right ? I try to translate these codes into Fortran. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:So, it is because the C code is wrong... The correct one is n1=new int;Quote:
emreka82 wrote:Hi,
....
int *n1, b;
float **n2, **n3;
n1= new float ;
n2= new float *;
n3= new float *;
for(int j=0;j<b;j++)
{
ge>>n1
; n2
= new float [n1 ]; n3
= new float [n1 ]; for(int i=0;i<n
;i++) {
ge>>n2
>>n3 ; }
}
...
I understand the code, it is the indirection and multiple indirection and allocation, right ? I try to translate these codes into Fortran. Thanks
The above program is in error. "n1= new float ;" is allocating an array of floats and assigning its pointer to the int* n1.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Repeat Offender wrote:I know, I only cut a part of a code and now I'm simply trying to understand the codes. 2.The C++ code in your last post, besides being incomplete, has many errors........
Repeat Offender wrote:The case between sss and nnn gives that: class ccc { double ***sss } 7 ccc *nnn; 17 delete nnn->sss; 20 nnn->sss= new double **[2]; 24 nnn->sssBut -> is an operator in C such that nnn->sss means (*nnn).sss, that is, dereference nnn so that we are now talking about the structure of type ccc that nnn points at rather than the address in memory of the structure, which is nnn's value, and look at the sss component of that structure, which is a pointer to a pointer to a pointer to double.
Repeat Offender wrote:Then C uses the equal (=) sign such as in lines 35, 36 and 53 right ? and Fortran should use the arrow (=>) in that cases.The => symbol in Fortran can be a rename operator in the sense of
use my_module, extra_crispy_name =>; original_name
or as the symbol in a pointer assignment,like
a => b
If b is a pointer, it means that pointer a points at the target of b; if b is a target, it means that pointer a points at b. Fortran needs a special symbol for this because
a = b
is already taken, meaning that the target a points at gets assigned the data of b (or the data of the target of b if b is a pointer).
Repeat Offender wrote:They surely have bunch of errors, but I only write down here, sorry for that...The correct one must be %. 4. By the way I didn't understand the ISO_C_BINDING thing also... Glad to have this discussion and learn lots of things, thanks again. Sincerely yours, EmreSo the -> operator should normally be replaced simply by % in Fortran because dereferencing is implict in most syntax containing a pointer, except for ALLOCATE, DEALLOCATE, ASSOCIATED, C_F_POINTER, pointer assignment(=>), and when passing a pointer as an actual argument to a pointer dummy argument. If your replacements for lines 17 and 20 don't cause your compiler to spit out a bunch of error messages, send in a bug report.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Repeat Offender wrote:Also, as I saw in Metcalf's notes http://w3.pppl.gov/~hammett/comp/f90tut/f90.tut6.html , arrays of pointers in fortran are not the same as C pointers. I will try to handle the C codes (above mentioned) by defining a derived data type with a pointer as its sole component...Way too time consuming...............

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page