[Coco] Found strangeness in C compiler (bug)

Allen Huffman alsplace at pobox.com
Tue May 21 08:16:25 EDT 2019


> On May 21, 2019, at 7:12 AM, Mathew Boytim via Coco <coco at maltedmedia.com> wrote:
> 
> I agree the result is undefined.  This is what gcc has to say
> main.c:7:4: warning: operation on ‘da’ may be undefined [-Wsequence-point] *da++ = *dN++ * v - *da; // this is correct as the increment should happen after the assignment  ~~^~
> 
> The standard doesn't say when the pointer is incremented, it only says where the result will be stored so you can't say "the increment will happen after the assignment".  I have to agree that the behavior is not what I would expect but undefined is undefined.  Bottom line is that you can't do that and expect it to be predictable.
> Matt

When I worked for Microware, we’d often receive customer support calls about the compiler doing something odd. We’d run it by the compiler group, and more often than not, they’d respond with the bit from the ANSI spec explaining that what the customer was doing was “undefined” and shouldn’t be done that way.

I find it interesting that many of these undefined things are finally getting defined in later versions of the spec (someone mentioned C 17).

		— Allen



More information about the Coco mailing list