ID Number: Q72417
6.00 6.00a 6.00ax | 6.00 6.00a
MS-DOS | OS/2
buglist6.00 buglist6.00a buglist6.00ax fixlist7.00
Summary:
SYMPTOMS
The Microsoft C versions 6.0, 6.0a, and 6.0ax and QuickC versions
2.5 and 2.51 compilers may generate incorrect code for function
arguments when using _based pointer types. This problem occurs only
when an argument is cast to a _based pointer and the preceding
argument is a string literal.
RESOLUTION
To work around the problem, either use a temporary variable to
calculate the value before the function call, or replace the _based
pointer cast with some other type (near ptr, far ptr, unsigned, and
so forth).
STATUS
Microsoft has confirmed this to be a problem in C versions 6.0,
6.0a, and 6.0ax and QuickC versions 2.5 and 2.51 (buglist2.50 and
buglist2.51). This problem was corrected in C/C++ version 7.0.
More Information:
The sample code below illustrates this problem. When the code is
compiled in any memory model with any optimization, the compiler
generates incorrect string constants for the first argument to the
func() function. Instead of creating a string called "TestString", the
result is "_CODE\0ring" (the based segment name overwrites the
string).
Sample Code
-----------
/* Compile options needed: none
*/
#define bcs _based ( _segname("_CODE"))
int _cdecl printf( const char *, ... );
int _cdecl strcmp( const char *, const char * );
int func( char*, int );
int main( void );
void bcs *ptr1;
void bcs *ptr2;
int main( )
{
return(func("TestString", (char bcs *) ptr1 - (char bcs *) ptr2));
}
int func( char *TestStr, int IntVal )
{
if( strcmp( TestStr, "TestString" ) )
{
printf( "Failed\n" );
return( 1 );
}
else
{
printf( "Passed\n" );
return( 0 );
}
}
Additional reference words: 6.00 6.00a 6.00ax