- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have written a module ( a prt of it shown here) and subroutine inside it, as follows:
- module class_mg
- type ptr
- type(c), pointer :: pp
- end type ptr
- !............
- type c
- !............
- integer c_no
- type(c), pointer :: prnt=>NULL()
- type(ptr), pointer :: ng(:)=>NULL()
- type(ptr), pointer :: ch(:)=>NULL()
- integer compc
- !............
- end type c
- !............
- type(c), pointer :: root
- !............
- !............
- contains
- recursive subroutine set_ng(c_no, root)
- type(c), pointer :: root
- if(c_no==0) then
- !............
- root%ng(3)%pp=>root%prnt%ch(3)%pp
- root%ng(2)%pp=>root%prnt%ch(1)%pp
- if(root%prnt%ng(1)%pp /= 0 .and. root%prnt%ng(1)%pp%compc==0) then
- root%ng(1)%pp=>root%prnt%ng(1)%pp%ch(3)%pp
- root%prnt%ng(1)%pp%ch(3)%pp%ng(3)%pp=>root
- end if
- !............
- end if
- end subroutine set_ng
- end module class_mg
The code fails to compile, returning the following error message in line 26: error #6355: This binary operation is invalid for this data type. [PP]
Am I doing something wrong? Thanks
Emre K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
if(root%prnt%ng(1)%pp /= 0attempts to compare a value of type integer to a component of type pointer variable of type(c), and
root%prnt%ng(1)%pp%compc==0compares a component of type integer to an integer. The former comparison is invalid; nor is it clear what the intended effect may be.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mecej4 wrote:Actually, I want to wrote: if(root%prnt%ng(1) /= 0, but because of the array definition in a pointer does not work like this in Fortran, I have to show it with a ragged array and use pp... So I want to say that if the first holder of the array ng is not equal to zero then if condition can be used. Is it clear ? When I do that thing with the C++ code (such as; root->prnt->ng[1] != 0 ) in a similar fashion, there is no error, which is also interesting for me...if(root%prnt%ng(1)%pp /= 0
attempts to compare a value of type integer to a component of type pointer variable of type(c), and
root%prnt%ng(1)%pp%compc==0
compares a component of type integer to an integer.
The former comparison is invalid; nor is it clear what the intended effect may be.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:Steve, Shouldn't I have to nullify the pointer before allocate it, and also at the end of the use deallocate ? ASSOCIATED is the checking of it, right ?Use ASSOCIATED to ask if the pointer is associated (not null).
- 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
Steve Lionel (Intel) wrote:Steve, Then, where do I need ASSOCIATE declaration inside my code, is it necessary ? More importantly, can it solve my "invalid data type" problem ? Thanks. EmreYes, you should have added a default initialization for pp to NULL() as was done for other pointer components. The DEALLOCATE will set it to null automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Whether this change will enable your code to function properly, however, is not something that one can answer, given the fragmentary view that has been divulged.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mecej4 wrote:Thanks mecej, I have a minor problem besides these, for example: In c++: if(*root->type==out && intersect==2) { *root->type=split; } and out and split are the enumerated types, such as: enum ctype { out, cut, inside, split}; In Fortran, the following works for the first line, but it does not work inside the if clause : if(associated(root%type_%out) .and. intersect==2) then associated(root%type_%split) end if The problems are the enumerated filetypes and "*root->type=split" inside the if clause. Thanks again.Steve's suggestion was to replace the invalid statement
if(root%prnt%ng(1)%pp /= 0)withif(associated(root%prnt%ng(1)%pp))....
Whether this change will enable your code to function properly, however, is not something that one can answer, given the fragmentary view that has been divulged.
- 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
mecej4 wrote:First of all, the codes that I try to write down are very long but there are troublesome "tricky" points inside some of the codes, which are discussed here. My example starts inside the datastructure class, a enumeration type, as I said before: C++: [cpp] //datastr.h: #ifndef DATASTR #define DATASTR enum ctype { out, cut, in, split}; // continues... class c { public: // continues... ctype *type; int *sq_i; // continues... }; #endif [/cpp] [cpp] //mg.h #ifndef MG #define MG using namespace std; #include "datastr.h" class mg : public c { public: // continues... c *root; // continues... }; #endif [/cpp] [cpp] // sq_i.cpp #include "mg.h" void mg::sq_i(c *nov) // continues... int intersec(0); if (*nov->type==out && intersec>2) { exit(EXIT_FAILURE); } else { *nov->type=split; *nov->sq_i=-40; } // continues... } [/cpp] [cpp] // create.cpp #include "mg.h" void mg::create() { root = new c; // continues... sq_i(root); // continues... } [/cpp] I am trying to write in Fortran form. Fortran: [fortran] module class_datastr type ctype integer, pointer :: out, cut, in, split end type ctype ! continues... type c ! continues... type(ctype), pointer :: type_ integer, pointer :: sq_i ! continues... end type c end module class_datastr [/fortran] [fortran] module class_mg use class_datastr ! continues... type(c), pointer :: root ! continues... end module class_mg [/fortran] [fortran] recursive subroutine mg_sq_i(nov) use class_mg type(c), pointer :: nov ! continues... integer intersec ! continues... if(associated(nov%type_%out) .and. intersec>2) then exit else associated(nov%type_%split) nov%sq_i=-40 end if ! continues... end subroutine sq_i [/fortran] [fortran] subroutine mg_create use class_mg allocate(root) ! continues... call sq_i(root) ! continues... end subroutine mg_create [/fortran] Above, I write some parts of the modules(classes) and subroutines, selected from my codes. The problem is the *nov->type=split; line inside the create.cpp code. I wish you understand the issue here. Thanks for the effort mecej.
.......Because you have only shown code fragments (in particular, the data type mapping from C to Fortran is not shown completely), it is not feasible for me to guess what you wish to accomplish. ...

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