Cannot define a string having blanks as a macro value.

Cannot define a string having blanks as a macro value.

I need to generate a message whose content I wish to pass at compile time using the option  -Dname="string".

It seems impossible to pass a string having blanks, whatever combination of single and/or double quotes I use.

The documentation simply states ( ) :

-Dname=value :
value : Is an optional integer or an optional character string delimited by double quotes; for example, Dname=string.

without any advice about the string content.

Here is a simple example.

$ cat testfppi.f

# NB : here the blanks between double and single quotes are for readability only, I did not use them actually.

$ ifort -V -fpp -E -DOPERATING_SYSTEM=" 'Red Hat Linux' "  testfppi.f                 
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 6, Version Build 20120731
Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.
ifort: error #10236: File not found:  'Hat'
ifort: error #10236: File not found:  'Linux'

# 1 "testfppi.f"
      PRINT *,Red

I also tried escaping the blanks by backslashes, without success.
Is that the intended way of working for "-D" ? Is there any way to have blanks in such a string ?

Thanks in advance.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The problem you are experiencing may be with your shell

$ ifort -V -fpp -E "-DOPERATING_SYSTEM=""'Red Hat Linux""" testfppi.fur

You will need to look at your shell/make documentation as to how to pass quotes. In the above I used two " marks. Your shell may have an alternate way to pass quotes.

Jim Dempsey

Thanks Jim.
You are right: the shell has a role in this issue. I use intermediate scripts for accessing different versions of the compiler, and subsequent passages of quoted arguments mess them up.
The direct access to the executable, after having run, gives the proper result once I used the following syntax (double quoting a single-quoted string):

ifort -V -fpp -DOPERATING_SYSTEM="'Red Hat Linux'" testfpp.f90

Leave a Comment

Please sign in to add a comment. Not a member? Join today