View previous topic :: View next topic |
Author |
Message |
Anonymous Guest
|
Posted: Sun Aug 20, 2006 1:37 am Post subject: Conditional compilation |
|
|
Hello,
Can somebody please help me with the following simplified piece of code?
PROGRAM TEST
IMPLICIT NONE
#define x
#ifdef x
PRINT*, 'ifdef works...'
#endif
#ifndef x
PRINT*, 'ifndef works...'
#endif
STOP
END PROGRAM TEST
It's the first time I'm trying to do something with preprosessor options and it doesn't work.
I'm compiling the program with "FTN95 TEST.F95 /CFPP" on the command line, with no errors, but on execution of the program NOTHING is printed to the screen.
So, I'm wondering was I'm doing wrong.
Kind regards |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Mon Aug 21, 2006 1:18 am Post subject: Conditional compilation |
|
|
Lucas
The #define and #ifdef work OK for me but #ifndef and the associated code is ignored.
At first sight there is something wrong with #ifndef. If it is not implemented by FTN95 then an error should be flagged.
I do not think that the outcome will depend on the version number of FTN95 because the feature was only added at about version 4.8 and to my knowledge there have been no changes made.
Are you sure you are not getting the first PRINT statement? Have you tried running from a DOS box?
The more common usage is to provide a value for the "SPECIAL PARAMETER" via the FTN95 command line so you may get better results this way.
|
|
Back to top |
|
|
Anonymous Guest
|
Posted: Mon Aug 21, 2006 3:02 am Post subject: Conditional compilation |
|
|
Paul,
Thanks for your reply, I am a step further now.
This time I tried the following code:
PROGRAM TEST
IMPLICIT NONE
INTEGER :: I = 0
#define x
#ifdef x
I = 1
#endif
#ifndef x
I = 2
#endif
WRITE(6,*) I
END PROGRAM
and ran it from a DOS-box. The result was 2.
I did expect a 1 however, so now is my question: where can I find more detailed info about compiler directives such as #define, #ifdef and #ifndef,...? Because the help file doesn't tell me that much in this case.
Regards, Lucas. |
|
Back to top |
|
|
Anonymous Guest
|
Posted: Mon Aug 21, 2006 4:27 am Post subject: Conditional compilation |
|
|
Addendum:
I had better tried this first before posting:
PROGRAM TEST
IMPLICIT NONE
INTEGER :: I = 0
#define x
#ifdef x
I = 1
WRITE(6,*) I
#endif
#ifndef x
I = 2
WRITE(6,*) I
#endif
END PROGRAM
The resulting output is
1
2
So it seems that the "variable" x is at the time defined and undefined?
Very strange. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Mon Aug 21, 2006 5:31 am Post subject: Conditional compilation |
|
|
Lucas
As I tried to say, #ifndef does not appear to be implemented in FTN95 and FTN95 should give an error report when an attempt is made to use #ifndef.
Avoid using #ifndef. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Tue Aug 22, 2006 9:54 am Post subject: Conditional compilation |
|
|
Lucas
#ifndef has now been fixed for the next release of FTN95. |
|
Back to top |
|
|
|