- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm having some troubles with declaring a global protected variable. Things like
MODULE test_protected PRIVATE TYPE test_type INTEGER :: number = 8 END TYPE test_type TYPE(test_type), PROTECTED :: myglobal_test END MODULE test_protected (...) PROGRAM tryme USE test_protected PRINT*,myglobal_test%number END PROGRAM tryme
does not seem to compile; it complains that the variable myglobal_test does not have a defined type. Making test_type public won't help. Also declaring PROTECTED :: myglobal_test instead of line 6 does not work. The only way I got to get it working was to declare
PRIVATE PUBLIC :: myglobal_test TYPE(test_type), PROTECTED :: myglobal_test
Apparently the second definition overwrites the first and the compiler does not complain (upon testing, the thing IS really protected and I cannot write into it from an external module).
Is this expected? Did I misunderstand the use of the protected statement?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your post was overlooked, our apologies. It came to light after the same question arose again here, https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/594444.
My reading is the difference between the two is “access” vs. “use”. PRIVATE / PUBLIC control “access” to module entities. PROTECTED specifies limitations on the “use” of module entities but it does not affect the "access". The error you noted is expected.
In your working solution, you could also combine further as:
TYPE(test_type), PUBLIC, PROTECTED :: myglobal_test

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