BUG: Error w/ CHAR() in WRITE of Unformatted or Binary Output

Last reviewed: February 29, 1996
Article ID: Q147756
The information in this article applies to:
  • Microsoft Fortran PowerStation for Windows 95 and Windows NT, version 4.0

SYMPTOMS

Writing unformatted character output to a file with a CHAR expression causes an application error similar to the following:

Under Windows NT version 3.51:

   Application Error -  The instruction at 0x0040a9ba referenced
   memory at 0x00000041. The memory could not be read

Under Windows 95:

   This program has performed an illegal operation and will be shut down.
   If the problem persists, contact the program vendor.

-or-

Writing binary character output to a file with a CHAR expression causes an application error similar to the following:

Under Windows NT version 3.51:

   Application Error - The instruction at 0x0040a773 referenced
   memory at 0x00000041. The memory could not be read.

Under Windows 95:

   This program has performed an illegal operation and will be shut down.
   If the problem persists, contact the program vendor.

RESOLUTION

Perform intermediate calculations in a temporary variable. Then use it in the CHAR() expression.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following code demonstrates the problem writing unformatted output:

Sample Code

C Compile options needed: none

      integer len
      len = 66
      open(1,file='t.out',form='unformatted')

C The following line causes an Access violation
      write(1) char(len-1) ! Comment this line for workaround

C To workaround the problem perform intermediate calculations C in a temporary variable and use it in the char() expression.

C      i = len - 1         ! Uncomment this line for workaround
C      write(1) char(i)    ! Uncomment this line for workaround

      close(1)
      end

The following code demonstrates the problem writing binary output:

Sample Code

C Compile options needed: none

      integer len
      len = 66
      open(1,file='t.out',form='binary')

C The following line causes an Access violation
      write(1) char(len-1) ! Comment this line for workaround

C To workaround the problem perform intermediate calculations C in a temporary variable and use it in the char() expression.

C      i = len - 1         ! Uncomment this line for workaround
C      write(1) char(i)    ! Uncomment this line for workaround

      close(1)
      end


Additional reference words: 4.00
KBCategory: kbprg kbbuglist
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.