I'm just starting out on Fortran and am confused with the usage of double vs single quotation marks.
Asked
Active
Viewed 4,053 times
13
-
This is a good question. As has been answered already, there are only subtle differences when formatting output. This is in contrast to C or C++, where they enclose different data structures. – Raul Laasner Jun 23 '15 at 08:53
2 Answers
14
They are equivalent. There is no difference in their usage.
You can employ this to print one of the quotation characters:
print *, "'"
print *, '"'
prints first '
and then "
.
Note: You can also use two quote characters in a row to print one:
print *, """"
print *, ''''
prints first "
and then '
.
![](../../users/profiles/721644.webp)
Vladimir F
- 50,383
- 4
- 60
- 96
0
Functionally they have no difference. Just try to be consistent about which one you use. If your strings tend to have double quotes in them, use single quotes everywhere; if you use single quotes more often, use double quotes to delimit your strings.
As an additional note, it is possible to escape the quote character inside a string: (i.e. 'You\'re'
) but most people would suggest using it doubled up as they would find it more readable (i.e. 'You''re'
).
![](../../users/profiles/4949262.webp)
everythingfunctional
- 601
- 7
- 12
-
1
-
This escaping, if allowed, will be processor-dependent, and best avoided as the standard way is as given. – francescalus Jun 23 '15 at 13:20
-
@francescalus, I didn't realize that. Thanks for the heads up. Do you know of any particular environment in which it isn't supported? – everythingfunctional Jun 24 '15 at 13:04
-
nagfor and ifort don't out of the box - I don't know whether they have control options to support this. – francescalus Jun 24 '15 at 13:10