- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all
I am trying to compile a test program pasted below, using the conditional compilation directive.
But it failed, Could anyone tell me where wrong is the program?
Module param
!DEC$ IF DEFINED (d1)
integer,parameter :: nc1 = 10
real*8 dx1
!DEC$ ELSE
integer,parameter :: nc1 = 10
integer,parameter :: nc2 = 10
real*8 dx1
real*8 dx2
!DEC$ ENDIF
end module
program main
use param
implicit none
!DEC$ IF DEFINED (d1)
call sub1
!DEC$ ELSE
call sub1
call sub2
!DEC$ ENDIF
end program
subroutine sub1
use param
implicit none
dx1 = 1.d0/ nc1
end subroutine
subroutine sub2
use param
implicit none
dx2 = 1.d0/ nc2
end subroutine
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If d1 is defined you don't declare the nc2 and dx2 module variables, but they are still referenced in sub2?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When d1 is defined, sub2 is invalid (uses undefined variables). Conditionalize it out.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
Thank you for your early reply.
As you said, I modified this test program as follows:
!DEC$ IF DEFINED (d1)
subroutine sub1
use param
implicit none
dx1 = 1.d0/ nc1
end subroutine
!DEC$ END IF
!DEC$ IF DEFINED (d2)
subroutine sub2
use param
implicit none
dx2 = 1.d0/ nc2
end subroutine
!DEC$ END IF
Is there any other way to do so?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ifort supports #ifdef ... #endif with /fpp option. Don't know if that's what you mean by "any other way."

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