BUG: Passing LOC() Intrinsic Result to C Function Fails

Last reviewed: March 8, 1996
Article ID: Q148203
The information in this article applies to:

  - Microsoft Fortran PowerStation for Windows 95 and Windows NT,
    version 4.0

SYMPTOMS

Using a variable character substring as an argument to the LOC() intrinsic function and passing the result to a C function causes the variable character substring to become corrupted.

RESOLUTION

  • Use a literal character substring as the LOC() intrinsic argument.

    -or-

  • Assign the variable character substring to a temporary character variable, and use it as the LOC() intrinsic argument.

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

Sample Code to Illustrate Problem and Workarounds

C Fortran Main Source Code C Compile options needed: none

      INTERFACE
          SUBROUTINE MYFUNC(I)
          INTEGER I
          !MS$ATTRIBUTES VALUE :: I
          !MS$ATTRIBUTES C,ALIAS:'_myfunc' :: myfunc
          END SUBROUTINE MYFUNC
      END INTERFACE

      CHARACTER STR*3, TEMP*4
      INTEGER L

      STR = 'ABC'
      L = 3

C this fails
      CALL MYFUNC(LOC(STR(1:L)//CHAR(0)))

C these work
      CALL MYFUNC(LOC(STR//CHAR(0)))
      CALL MYFUNC(LOC(STR(1:3)//CHAR(0)))
      TEMP=STR(1:L)//CHAR(0)
      CALL MYFUNC(LOC(TEMP))
      END

/* C Function Source Code:
   Compile options needed: /c
*/

#include <stdio.h>
void myfunc(char *s)
{
    long x;
    x = (long) s;
    printf("s: %x  String: %s\n", x, s);
}

Program Output

s: 12ffa8 String: - s: 12ffa4 String: ABC s: 12ffa0 String: ABC s: 41bac8 String: ABC


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: March 8, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.