From -4504486881183913904
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7522e5259f7267d6
X-Google-Attributes: gidf78e5,public
From: Francis Glassborow <francis@robinton.demon.co.uk>
Subject: x = y = z; Undefined?
Date: 2000/01/14
Message-ID: <ODLm8FBVGgf4Ewho@robinton.demon.co.uk>#1/1
X-Deja-AN: 572396849
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <MPG.12ddaa92533ae9679896a6@news.supernews.com> <t7so0bqea7.fsf@calumny.jyacc.com> <3876254a.30903561@news.csrlink.net> <derobert-9FC87E.01591309012000@news.erols.com> <3879ca08.3142429@news.csrlink.net> <derobert-8223E1.23372510012000@news.erols.com> <387b3c32.7816532@news.csrlink.net> <387B6338.FCE9D984@sensor.com> <387bb7c0.39451037@news.csrlink.net> <387C7098.256766C8@wizard.net> <387cde71.28276175@news.csrlink.net> <387D1FC3.F19D5853@wizard.net> <387d50e4.57579814@news.csrlink.net>
X-UID: 0000000001
X-Status: $$$T
Organization: Southfield Microcomputer SS
Mime-Version: 1.0
Reply-To: Francis Glassborow <francisG@robinton.demon.co.uk>
Newsgroups: comp.std.c++
Originator: clamage@taumet


In article <387d50e4.57579814@news.csrlink.net>, John Potter
<jpotter@falcon.lhup.edu> writes
>   int i1, i2(2), i3(3);
>   (i1 = i2) += i3;
>   cout << i1 << endl;

Any compiler of reasonable quality should be able to get such code
correct because the potential undefined behaviour has not been hidden
(e.g. by aliasing).  I understood that one reason for writing the rules
the way they are was that some systems have serious problems in writing
to the same store with insufficient delay.  Note that I am not a
hardware expert and so this is hearsay.

IMO compiler writers could do a much better job at detecting potential
undefined behaviour and at least issuing a warning.  Code such as:

int i = 0;
int array[10];
while (i<10) array[i] = i++;

Has an easily diagnosed problem, it would be helpful if compilers issued
warning for such code even if they include an assurance that they will
generate safe code.

OTOH

void fn (int & i, int & j, int max, int * array) {
        i=0;
        while (i< max) array[i++] = j++;
}

Has potentially far worse undefined behaviour which cannot be reasonably
diagnosed.  Yes, I know the code stinks but have a look at some real
code and you will find things just as rotten only masked by other code.



Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




