diff options
author | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-12-08 21:46:56 +0000 |
---|---|---|
committer | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-12-08 21:46:56 +0000 |
commit | 9ba02d19e0b62607b292ef5da23173fe3691f419 (patch) | |
tree | 68c3248c30a91eca167c87f49666a1386e036a1c /gcc/fortran/gfortran.texi | |
parent | ce6a87f898b1ea4fc9678bc703727441f99ad864 (diff) | |
download | gcc-9ba02d19e0b62607b292ef5da23173fe3691f419.tar.gz |
2007-12-08 Tobias Burnus <burnus@net-b.de>
PR fortran/34342
PR fortran/34345
PR fortran/18026
PR fortran/29471
* gfortran.texi (BOZ literal constants): Improve documentation
and adapt for BOZ changes.
* Make-lang.ini (resolve.o): Add target-memory.h dependency.
* gfortran.h (gfc_expr): Add is_boz flag.
* expr.c: Include target-memory.h.
(gfc_check_assign): Support transferring BOZ for real/cmlx.
* resolve.c: Include target-memory.h
(resolve_ordinary_assign): Support transferring BOZ for real/cmlx.
* target-memory.c (gfc_convert_boz): New function.
* target-memory.c (gfc_convert_boz): Add prototype.
* primary.c (match_boz_constant): Set is_boz, enable F95 error
also without -pedantic, and allow for Fortran 2003 BOZ.
(match_real_constant): Fix comment.
* simplify.c
* (simplify_cmplx,gfc_simplify_dble,gfc_simplify_float,
gfc_simplify_real): Support Fortran 2003 BOZ.
2007-12-08 Tobias Burnus <burnus@net-b.de>
PR fortran/34342
PR fortran/34345
PR fortran/18026
PR fortran/29471
* gfortran.dg/boz_8.f90: New.
* gfortran.dg/boz_9.f90: New.
* gfortran.dg/boz_10.f90: New.
* gfortran.dg/boz_7.f90: Update dg-warning.
* gfortran.dg/pr16433.f: Add dg-error.
* gfortan.dg/ibits.f90: Update dg-warning.
* gfortran.dg/unf_io_convert_1.f90: Update/delete dg-warning.
* gfortran.dg/unf_io_convert_2.f90: Ditto.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130713 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/gfortran.texi')
-rw-r--r-- | gcc/fortran/gfortran.texi | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 095517d8452..84795fb016d 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -862,6 +862,9 @@ Renaming of operators in the @code{USE} statement. @cindex ISO C Bindings Interoperability with C (ISO C Bindings) +@item +BOZ as argument of INT, REAL, DBLE and CMPLX. + @end itemize @@ -1084,26 +1087,45 @@ of the @code{READ} statement, and the output item lists of the @section BOZ literal constants @cindex BOZ literal constants +Besides decimal constants, Fortran also supports binary (@code{b}), +octal (@code{o}) and hexadecimal (@code{z}) integer constants. The +syntax is: @samp{prefix quote digits quote}, were the prefix is +either @code{b}, @code{o} or @code{z}, quote is either @code{'} or +@code{"} and the digits are for binary @code{0} or @code{1}, for +octal between @code{0} and @code{7}, and for hexadecimal between +@code{0} and @code{F}. (Example: @code{b'01011101'}.) + +Up to Fortran 95, BOZ literals were only allowed to initialize +integer variables in DATA statements. Since Fortran 2003 BOZ literals +are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT} +and @code{CMPLX}; the result is the same as if the integer BOZ +literal had been converted by @code{TRANSFER} to, respectively, +@code{real}, @code{double precision}, @code{integer} or @code{complex}. +The GNU Fortran intrinsic procedure @code{FLOAT}, @code{DFLOAT}, +@code{COMPLEX} and @code{DCMPLX} are treated alike. + As an extension, GNU Fortran allows hexadecimal BOZ literal constants to -be specified using the X prefix, in addition to the standard Z prefix. -BOZ literal constants can also be specified by adding a suffix to the -string. For example, @code{Z'ABC'} and @code{'ABC'Z} are equivalent. - -The Fortran standard restricts the appearance of a BOZ literal constant -to the @code{DATA} statement, and it is expected to be assigned to an -@code{INTEGER} variable. GNU Fortran permits a BOZ literal to appear in -any initialization expression as well as assignment statements. - -Attempts to use a BOZ literal constant to do a bitwise initialization of -a variable can lead to confusion. A BOZ literal constant is converted -to an @code{INTEGER} value with the kind type with the largest decimal -representation, and this value is then converted numerically to the type -and kind of the variable in question. Thus, one should not expect a -bitwise copy of the BOZ literal constant to be assigned to a @code{REAL} -variable. - -Similarly, initializing an @code{INTEGER} variable with a statement such -as @code{DATA i/Z'FFFFFFFF'/} will produce an integer overflow rather +be specified using the @code{X} prefix, in addition to the standard +@code{Z} prefix. The BOZ literal can also be specified by adding a +suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are +equivalent. + +Furthermore, GNU Fortran allows using BOZ literal constants outside +DATA statements and the four intrinsic functions allowed by Fortran 2003. +In DATA statements, in direct assignments, where the right-hand side +only contains a BOZ literal constant, and for old-style initializers of +the form @code{integer i /o'0173'/}, the constant is transferred +as if @code{TRANSFER} had been used. In all other cases, the BOZ literal +constant is converted to an @code{INTEGER} value with +the largest decimal representation. This value is then converted +numerically to the type and kind of the variable in question. +(For instance @code{real :: r = b'0000001' + 1} initializes @code{r} +with @code{2.0}.) As different compilers implement the extension +differently, one should be careful when doing bitwise initialization +of non-integer variables. + +Note that initializing an @code{INTEGER} variable with a statement such +as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather than the desired result of @math{-1} when @code{i} is a 32-bit integer on a system that supports 64-bit integers. The @samp{-fno-range-check} option can be used as a workaround for legacy code that initializes |