BOZ-literal-constants.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1999-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>The GNU Fortran Compiler: BOZ literal constants</title>
  20. <meta name="description" content="The GNU Fortran Compiler: BOZ literal constants">
  21. <meta name="keywords" content="The GNU Fortran Compiler: BOZ literal constants">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Extensions-implemented-in-GNU-Fortran.html#Extensions-implemented-in-GNU-Fortran" rel="up" title="Extensions implemented in GNU Fortran">
  30. <link href="Real-array-indices.html#Real-array-indices" rel="next" title="Real array indices">
  31. <link href="Q-exponent_002dletter.html#Q-exponent_002dletter" rel="prev" title="Q exponent-letter">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="BOZ-literal-constants"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Real-array-indices.html#Real-array-indices" accesskey="n" rel="next">Real array indices</a>, Previous: <a href="Q-exponent_002dletter.html#Q-exponent_002dletter" accesskey="p" rel="prev"><code>Q</code> exponent-letter</a>, Up: <a href="Extensions-implemented-in-GNU-Fortran.html#Extensions-implemented-in-GNU-Fortran" accesskey="u" rel="up">Extensions implemented in GNU Fortran</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="BOZ-literal-constants-1"></a>
  69. <h4 class="subsection">6.1.9 BOZ literal constants</h4>
  70. <a name="index-BOZ-literal-constants"></a>
  71. <p>Besides decimal constants, Fortran also supports binary (<code>b</code>),
  72. octal (<code>o</code>) and hexadecimal (<code>z</code>) integer constants. The
  73. syntax is: &lsquo;<samp>prefix quote digits quote</samp>&rsquo;, were the prefix is
  74. either <code>b</code>, <code>o</code> or <code>z</code>, quote is either <code>'</code> or
  75. <code>&quot;</code> and the digits are for binary <code>0</code> or <code>1</code>, for
  76. octal between <code>0</code> and <code>7</code>, and for hexadecimal between
  77. <code>0</code> and <code>F</code>. (Example: <code>b'01011101'</code>.)
  78. </p>
  79. <p>Up to Fortran 95, BOZ literals were only allowed to initialize
  80. integer variables in DATA statements. Since Fortran 2003 BOZ literals
  81. are also allowed as argument of <code>REAL</code>, <code>DBLE</code>, <code>INT</code>
  82. and <code>CMPLX</code>; the result is the same as if the integer BOZ
  83. literal had been converted by <code>TRANSFER</code> to, respectively,
  84. <code>real</code>, <code>double precision</code>, <code>integer</code> or <code>complex</code>.
  85. As GNU Fortran extension the intrinsic procedures <code>FLOAT</code>,
  86. <code>DFLOAT</code>, <code>COMPLEX</code> and <code>DCMPLX</code> are treated alike.
  87. </p>
  88. <p>As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
  89. be specified using the <code>X</code> prefix, in addition to the standard
  90. <code>Z</code> prefix. The BOZ literal can also be specified by adding a
  91. suffix to the string, for example, <code>Z'ABC'</code> and <code>'ABC'Z</code> are
  92. equivalent.
  93. </p>
  94. <p>Furthermore, GNU Fortran allows using BOZ literal constants outside
  95. DATA statements and the four intrinsic functions allowed by Fortran 2003.
  96. In DATA statements, in direct assignments, where the right-hand side
  97. only contains a BOZ literal constant, and for old-style initializers of
  98. the form <code>integer i /o'0173'/</code>, the constant is transferred
  99. as if <code>TRANSFER</code> had been used; for <code>COMPLEX</code> numbers, only
  100. the real part is initialized unless <code>CMPLX</code> is used. In all other
  101. cases, the BOZ literal constant is converted to an <code>INTEGER</code> value with
  102. the largest decimal representation. This value is then converted
  103. numerically to the type and kind of the variable in question.
  104. (For instance, <code>real :: r = b'0000001' + 1</code> initializes <code>r</code>
  105. with <code>2.0</code>.) As different compilers implement the extension
  106. differently, one should be careful when doing bitwise initialization
  107. of non-integer variables.
  108. </p>
  109. <p>Note that initializing an <code>INTEGER</code> variable with a statement such
  110. as <code>DATA i/Z'FFFFFFFF'/</code> will give an integer overflow error rather
  111. than the desired result of <em>-1</em> when <code>i</code> is a 32-bit integer
  112. on a system that supports 64-bit integers. The &lsquo;<samp>-fno-range-check</samp>&rsquo;
  113. option can be used as a workaround for legacy code that initializes
  114. integers in this manner.
  115. </p>
  116. <hr>
  117. <div class="header">
  118. <p>
  119. Next: <a href="Real-array-indices.html#Real-array-indices" accesskey="n" rel="next">Real array indices</a>, Previous: <a href="Q-exponent_002dletter.html#Q-exponent_002dletter" accesskey="p" rel="prev"><code>Q</code> exponent-letter</a>, Up: <a href="Extensions-implemented-in-GNU-Fortran.html#Extensions-implemented-in-GNU-Fortran" accesskey="u" rel="up">Extensions implemented in GNU Fortran</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  120. </div>
  121. </body>
  122. </html>