Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

PROTECTED as a statement

holysword
Novice
367 Views

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?

0 Kudos
1 Reply
Kevin_D_Intel
Employee
367 Views

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

0 Kudos
Reply