KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q67035: DS Used Instead of Base Segment for Based Pointer Dereference

Article: Q67035
Product(s): See article
Version(s): 6.00 6.00a | 6.00 6.00a
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | S_QUICKC buglist6.00 buglist6.00a | mspl13_c
Last Modified: 18-NOV-1990

There are some situations where a based pointer will be incorrectly
dereferenced in relation to the default data segment, rather than the
segment on which the pointer is based. This problem occurs only with
the QuickC Compiler or when the /qc (quick compile) option is used
with the C Optimizing Compiler.

The sample program below demonstrates this problem. When the code is
compiled with C versions 6.00 or 6.00a and the /qc option, the value
returned from the function is DS:0, instead of 0:0. By eliminating the
/qc option, the expected value is returned.

Microsoft has confirmed this to be a problem in C versions 6.00 and
6.00a and QuickC versions 2.50 and 2.51. We are researching this
problem and will post new information here as it becomes available.

Sample Code
-----------

#include <stdio.h>
#include <stdlib.h>

char far *get_address(void);

void main(void)
{
    char far *addr;

    addr = get_address();
    printf("Address = %Fp -- Address expected = 0000:0000\n", addr);
}

char far *get_address(void)
{
    _segment base = 0;

    return ( (char far *)(base:>NULL) );
}

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.

Copyright Microsoft Corporation 1986-2002.