Newsgroups: comp.lang.c++
Path: utzoo!utgpu!cunews!csi.uottawa.ca!news
From: hitz@sim5.csi.uottawa.ca (Martin Hitz)
Subject: Semantics of default assignment operator
Message-ID: <1991Mar22.172508.1881@csi.uottawa.ca>
Keywords: assignment operator
Sender: Martin Hitz (hitz@csi.UOttawa.CA)
Nntp-Posting-Host: sim5
Organization: University of Ottawa
Distribution: na
Date: Fri, 22 Mar 91 17:25:08 GMT

I recently came across the following incompatibility between
C and C++:
If a structure X contains an array, then the assignment
	
	struct X a, b;
	/* ..... */
	b = a;

is well defined in C and older C++ versions (bitwise copy).
 
Now, as C++ adopted the memberwise assignment semantics, it is not clear
to me what should happen, as there is no such thing as assignment to
arrays.

Trying doesn't help: The following program prints
	1 1 1	
with g++, and
	0 0 0
with Zortech.


Can anybody tell me, which is correct?

#include <stdio.h>
struct X
{
	int x[3];
};

main ()
{
	X a, b; 
	a.x[0] = a.x[1] = a.x[2] = 1;
	b.x[0] = b.x[1] = b.x[2] = 0;
	b = a;
	printf("%d %d %d\n", b.x[0], b.x[1], b.x[2]);
}


