Documentation Archive Developer
Search

ADC Home > Reference Library > Technical Q&As > Legacy Documents > Tools >

Legacy Documentclose button

Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.

Current information on this Reference Library topic can be found here:

NOTE: This Technical Q&A has been retired. Please see the Technical Q&As page for current documentation.

C++ Precedence Bug


Q: We're running MPW 3.3.1 with C++ on a Centris 660AV running System 7.5. All the MPW files are from a clean ETO #15.

According to Stroustrup (the C++ programming language) and the K&R C, the precedence of "<" is greater than the precedence of "!=", and all other references that we have agree with this. Since the two tests below return different results, MPW does not appear to be adhering to this rule. Both tests should succeed, but on MPW C++, test 1 fails. Under MPW 'C', this code works as it is supposed to.

-------------------------------------------------------------------------
#include <stdio.h>
main()
{
        puts("Starting Tests...");
        if (1 != 900 < 0)
                puts("Test 1 Worked");
        else
                puts("Test 1 Failed");
        if (1 != (900 < 0))
                puts("Test 2 Worked");
        else
                puts("Test 2 Failed");
}
-------------------------------------------------------------------------

To compile:
 CPlus -o tmp.o tmp.c
 Link -o tmp tmp.o "{CLibraries}"StdClib.o "{CLibraries}"CSANElib.o 6
                   "{CLibraries}"Math.o 6
                "{Libraries}"Runtime.o "{Libraries}"Interface.o 6
                "{Libraries}"ToolLibs.o

A: This is a bug, but since MPW is switching over to Mr C (Symantec C++ for MPW) as the main compiler, and this does not occur with SCpp, it is not likely to be fixed (maintenance on CFront has effectively stopped).

You have two choices: either explicitly specify precedence by using (), or switch to SCpp.

[Jun 01 1995]