Preprocessor directives ? 
Author Message
 Preprocessor directives ?


Quote:
>         I am translating some C code to fortran 90, and it has a few
preprocessor
> directives (#ifndef's, pragma's). Is it possible to seamlessly translate
> these ?

Check your compiler's documentation.  Many Fortran compilers can support
cpp-style conditional compilation (#ifdef), though you're unlikely to see
support for #pragma.  Such preprocessing is usually not on by default, and
some do not support macro substitution by default.

If you'd tell us which compiler you're using, someone familiar with it could
be of more assistance.

Standard Fortran, to date, does not define any sort of conditional
compilation facility, though there do exist add-on implementations that are
more "Fortran-like". Your best bet is to leave the conditional directives
alone and use your compiler's cpp-like support, if it has it.  For the
pragmas, research your compiler's documentation to see what it offers as
equivalents.  (For example, #pragma pack is often implemented by a compiler
directive or switch.)

Lastly, I'll note that use of such directives will make your code
non-portable, though the extent of the non-portability depends on exactly
what you end up using.

--
Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

Intel Fortran Support:
  http://www.*-*-*.com/

User communities for Intel Fortran and Visual Fortran:
  http://www.*-*-*.com/



Wed, 19 Jul 2006 21:33:17 GMT  
 Preprocessor directives ?

Quote:

> Lastly, I'll note that use of such directives will make your code
> non-portable, though the extent of the non-portability depends on exactly
> what you end up using.

Minor nitpick.... it needn't. I've used a code which did some makefile
magic - run cpp on the source code, and feed the result to the compiler.

This doesn't change most of your point, of course.

Richard



Wed, 19 Jul 2006 21:40:10 GMT  
 Preprocessor directives ?

Quote:
> > Lastly, I'll note that use of such directives will make your code
> > non-portable, though the extent of the non-portability depends on
exactly
> > what you end up using.

> Minor nitpick.... it needn't. I've used a code which did some makefile
> magic - run cpp on the source code, and feed the result to the compiler.

Minor nitpick - for the platforms you happen to have used.  I know of some
that don't have cpp nor "makefiles", unless you install some tools from
outside.

--
Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

Intel Fortran Support:
  http://developer.intel.com/software/products/support/

User communities for Intel Fortran and Visual Fortran:
  http://softwareforums.intel.com/



Thu, 20 Jul 2006 00:01:46 GMT  
 Preprocessor directives ?

Quote:

>>Minor nitpick.... it needn't. I've used a code which did some makefile
>>magic - run cpp on the source code, and feed the result to the compiler.

> Minor nitpick - for the platforms you happen to have used.  I know of some
> that don't have cpp nor "makefiles", unless you install some tools from
> outside.

Conceded :-)
That did occur to me about ten minutes after posting.

Richard



Thu, 20 Jul 2006 00:25:27 GMT  
 Preprocessor directives ?

Quote:


> > Lastly, I'll note that use of such directives will make your code
> > non-portable, though the extent of the non-portability depends on exactly
> > what you end up using.
> Minor nitpick.... it needn't. I've used a code which did some makefile
> magic - run cpp on the source code, and feed the result to the compiler.

Minor nitpic squared, the C preprocessor operates on C-language
tokens, not characters.  Not all legal Fortran constructs are made
up of legal C tokens, so the preprocessor may choke!  But this is
unusual.  Just another little thing to watch for.

--
pa at panix dot com



Thu, 20 Jul 2006 01:17:57 GMT  
 Preprocessor directives ?


Quote:


> > Minor nitpick - for the platforms you happen to have used.  I know of
some
> > that don't have cpp nor "makefiles", unless you install some tools from
> > outside.

> Thanks !

> I am using a Linux platform with IFC, but I wish to write the code so that
> it can work on any unix like system (would that include Mac OS X+ ?). I do
> not care if it does not work on windoze.

Too much context has been lost.  If you verified that your application
worked also with g77 (on linux or Windows), which uses the gnu tradcpp
pre-processor, your chances of working on most unix-like Fortran compilers
would be good.  You would also have the alternative, mentioned earlier, of
setting up a Makefile to invoke the gnu pre-processor.  If the system is
unix-like but does not come with those gnu tools, it should be possible to
install them.
There have been threads on this forum about Dan Nagle's Coco pre-processor,
which does adhere to a published Fortran standard.


Thu, 20 Jul 2006 02:25:25 GMT  
 Preprocessor directives ?

Quote:



>>> Lastly, I'll note that use of such directives will make your code
>>> non-portable, though the extent of the non-portability depends on
>>> exactly what you end up using.

>> Minor nitpick.... it needn't. I've used a code which did some makefile
>> magic - run cpp on the source code, and feed the result to the compiler.

> Minor nitpic squared, the C preprocessor operates on C-language
> tokens, not characters.  Not all legal Fortran constructs are made
> up of legal C tokens, so the preprocessor may choke!  But this is
> unusual.  Just another little thing to watch for.

In particular, be very careful of character concatenation (//) on
versions of the C preprocessor that have been extended to understand
C++ syntax.  In C++, the slash-slash is a comment marker.

--
J. Giles



Thu, 20 Jul 2006 07:47:21 GMT  
 Preprocessor directives ?


Quote:
> In particular, be very careful of character concatenation (//) on
> versions of the C preprocessor that have been extended to understand
> C++ syntax.  In C++, the slash-slash is a comment marker.

With the gcc compilers, either 'g77 -E' or 'gcc -E -traditional -x c'
invokes tradcpp ("traditional" cpp) which doesn't take // as having special
significance.


Thu, 20 Jul 2006 09:39:00 GMT  
 Preprocessor directives ?
Hello,

Be aware that macro substitution may push code past
column 72, in this case use whatever compiler switch
exists to tell the compiler to read past column 72.

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



Quote:



>> In particular, be very careful of character concatenation (//) on
>> versions of the C preprocessor that have been extended to understand
>> C++ syntax.  In C++, the slash-slash is a comment marker.

>With the gcc compilers, either 'g77 -E' or 'gcc -E -traditional -x c'
>invokes tradcpp ("traditional" cpp) which doesn't take // as having special
>significance.



Thu, 20 Jul 2006 21:55:45 GMT  
 Preprocessor directives ?


Hello,

Be aware that macro substitution may push code past
column 72, in this case use whatever compiler switch
exists to tell the compiler to read past column 72.

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



Quote:



>> In particular, be very careful of character concatenation (//) on
>> versions of the C preprocessor that have been extended to understand
>> C++ syntax.  In C++, the slash-slash is a comment marker.

>With the gcc compilers, either 'g77 -E' or 'gcc -E -traditional -x c'
>invokes tradcpp ("traditional" cpp) which doesn't take // as having special
>significance.

Until last month, macro substitution was broken for fixed form Intel
Fortran.  Even with that corrected, Dan's top-posted comment is well taken.


Thu, 20 Jul 2006 22:43:14 GMT  
 Preprocessor directives ?

Quote:

> Standard Fortran, to date, does not define any sort of conditional
> compilation facility, though there do exist add-on implementations that are
> more "Fortran-like".

I thought Part 3 of Fortran 95 defined conditional compilation and was
implemented in the coco precompiler?

David



Fri, 21 Jul 2006 16:29:38 GMT  
 Preprocessor directives ?
Hello,

Part 3 is optional, and not often implemented.

I have a coco available via
http://users.erols.com/dnagle/coco.html

This coco supports macros and will wrap lines
if asked.

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



Quote:

>> Standard Fortran, to date, does not define any sort of conditional
>> compilation facility, though there do exist add-on implementations that are
>> more "Fortran-like".

>I thought Part 3 of Fortran 95 defined conditional compilation and was
>implemented in the coco precompiler?

>David



Sat, 22 Jul 2006 01:11:09 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Preprocessor directives

2. preprocessor directives?

3. including preprocessor directives in included file

4. Preprocessor directives

5. f2c problem. f2c Doesn't understand preprocessor directives.

6. Correction (ETA optimizing preprocessor, Convex preprocessor)

7. Dummy section assembler directives

8. dummy section directives

9. Compiler directives and parsing (in VW en GS/S)

10. Need help with #Directives in CA Clipper 5.2

11. Directive #Translate.

12. #xcommand/#xtranslate directive

 

 
Powered by phpBB® Forum Software