Silverfrost Forums

Welcome to our forums

Precompiler flags ?

13 Jul 2006 6:09 #862

Hi,

I've been wondering if it is possible to use precompiler flags with FTN95, for example like this

#define keyword (some code) #ifdef keyword (some code) #endif

in order to be able to switch parts of the code easily on or off for compilation. I remember having seen these in a Fortran program by someone else and I have used them in C++. Is this possible with FTN95 too ?

Thanks Rainer

13 Jul 2006 8:29 #863

Rainer

Yes there are two ways to do this with FTN95.

You can use CIF or #ifdef. Both are described in the help file. Be careful if you are familiar with C and #ifdef etc because the behaviour in FTN95 is limited and slightly different. Work from very simple examples and then build up from this.

14 Jul 2006 5:52 #864

Hi Paul,

thanks for the help so far. But I've run into some problems. (I'm using FTN 95 v. 4.6.0.0.)

First, I tried the CIF family commands. The '/FPP' option was already checked in my compiler options, though I didn't specifically change any of the options. That was surprising, but not the actual problem. My source code looked like this:

PROGRAM mainprogram special parameter test /vparam test 1 ...

The line '/vparam test 1' got the error messages 'Invalid statement '/' at start of line' as well as 'Statement not recognized'. Replacing the line with '/sparam 1' had the same result. Without the '/', I simply get 'Statement not recognized'.


Then, I wanted to use the C style commands #ifdef, etc. I added '/cfpp' under 'Extra compiler options' and verified that the command was in the switches list. However, when compiling I got the message '/CFPP is not a valid option on the command line'. Without the option, naturally, any '#' symbol in the source code is flagged as an unknown symbol.


What also confuses me is that in the help file in the chapter 'C Style Conditional Compilation' the lines /VPARAM <name> <integer> /DEFINE <name> <integer> are described as 'command line switches'. I was thinking that command line switches were the additional options/switches given to the FTN95 executable, but these two lines were lines inside the source code.

Thanks for any advice. Rainer

17 Jul 2006 3:31 #866

Paul

There seems to have been a misunderstanding on my side as to how '/VPARAM' is used. Unfortunately, things are getting even more confusing. Let me explain.

From the FTN95 documentation:

'[big]Salford Conditional compilation[/big] FTN95 provides conditional compilation by means of the SPECIAL PARAMETER statement together with the /SPARAM and /VPARAM compile-time options and the CIF, CELSE and CENDIF statements.'

To me, 'compile-time option' could have meant either an option given to the compiler from the command line, that is a compiler switch. Or it could have meant a line of source code that is interpreted during compilation, before the actual source code. Because of what was stated in the documentation (see below), I understood it to be the latter. From what you are saying it seems to be the former.

The documentation continues:

'The specification statement SPECIAL PARAMETER <name> defines <name> to be of type integer. <name> must not appear in a type statement and is local to the program unit in which the SPECIAL PARAMETER statement appears. The value represented by <name> is set by means of the /SPARAM or /VPARAM compile-time option as follows: /SPARAM <integer> where <integer> is the required value.'

It seemed to me that 'SPECIAL PARAMETER <name>' was meant to be a line of source code. This also corresponds to the reference to 'program unit', which I assumed to be either the source files in the project (f95, inc, ...), or more likely the logical components, i.e. main program and modules. A compiler switch isn't local to any of these units. Hence, I assumed that the 'SPECIAL PARAMETER' line was meant to be in the source code. I further assumed it to be the declaration of the parameter, so it seemed logical that the assignment of a value to that parameter would come after the declaration and therefore also inside the source code. As I understood it, '/VPARAM' and '/SPARAM' are used to assign values to such special parameters. So, if '/VPARAM' is to be used as a compiler switch, what does 'SPECIAL PARAMETER' do and how is it used ?

17 Jul 2006 4:34 #867

Update:

I tried it with /VPARAM as a compiler switch and it works, with or without a 'SPECIAL PARAMETER' statement. Can it be that this statement is simply used to prevent other variables from having the same name as the special parameter ?

It also works without any /VPARAM switch. In this case, the special parameter checked with CIF apparently is assumed to be 0.

17 Jul 2006 8:50 #868

Rainer

Yes it looks like SPECIAL PARAMETER is not required in FTN95. It is throw back to FTN77. The parameter is used at pre-compile time so you will be able to use the same identifier for a different purpose in the compiled code.

Please login to reply.