Difference between double and single quotation marks in fortran?

5.5k views Asked by At

I'm just starting out on Fortran and am confused with the usage of double vs single quotation marks.

4

There are 4 answers

0
Vladimir F Героям слава On

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 '.

4
everythingfunctional On

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').

1
CRquantum On

there are some differences.

write (6,*) " Bruce's beard "

is fine and successfully print out Bruce's beard.

However,

write (6,*) '' Bruce's beard ''
write (6,*) ' Bruce's beard '

will not give you correct output which should be Bruce's beard.

0
francescalus On

Outside comments and character contexts, the special characters " (quotation mark/quote) and ' (apostrophe) are used in two ways:

  • delimiting a literal character constant, including one used as a character string edit descriptor
  • delimiting a BOZ literal constant

The syntax rules for both of these explicitly allow either " or ' to be used as a delimiter (but require the start and end delimiters to match, so they aren't quite interchangeable as characters), with no difference in interpretation between the two cases. (This contrasts with some other languages where only one form may be allowed, or each form may mean something different.)

In Fortran 2018, R724 allows both "A" and 'A' as literal character constants; R766 allows both O'1' and O"1" in specifying an octal constant. (Naturally, "A' and O"1' are not allowed by these rules.)

Within literal character constants/character contexts, as shown in other answers here, each special character represents its own particular form. Again, note from the other answers how, for example, '"A''A"' is to be interpreted.

Within a comment, neither character has any particular interpretation.