non-compliance of egcs/gcc/g++ with standard

Darel A Linebarger dl@utdallas.edu
Thu Oct 29 15:21:00 GMT 1998


Hello egcs folks,

I think that I may have found an example of non-compliance to the
standard. I am certainly seeing a difference between the behavior of
egcs/gcc and that of SUN's compiler.

MACHINE: SPARC Ultras (various flavors)

COMPILER VERSIONS:
	GNU egcs:
		Reading specs from
		/usr/local/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.57/specs
		gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

	GNU gcc/g++:
		Reading specs from
		/usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3/specs
		gcc version 2.7.2.3

	SUN:
		CC: WorkShop Compilers 4.2 30 Oct 1996 C++ 4.2

PROBLEM:
	By my reading of pg. 289 of "The annotated ref. manual C++"
first (1990)
edition (section 12.6.1 on Explicit Initialization), a partial
initializer list can be provided to an array of objects so long as a
default constructor is provided. In that case, the default constructor is
called for all elements of the array that are not explicitly initialized.
I see this kind of behavior from SUN's compiler in all cases, but I don't
see it from any of the GNU compilers if the array has more than 1
dimension.

Example program for 1D aray:
--------------------------------------------------------------------------
/* 
 * A test file for partially initialized 1D arrays of objects
 * The constructors for the class print out a member variable "name"
 * as they (the constructors) are called. The program then prints the 
member
 * variable "name" for one of the uninitialized array elements. The
default
 * constructor should be called N-1 (N is 3 in the example below) times.
 */

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

class dyn_temp {
public:

 char name[100];

 dyn_temp(char *name_in) {
	strcpy(name,name_in);
	printf("%s\n",name);
 }
 dyn_temp() {
	strcpy(name,"nothing");
	printf("%s\n",name);
 }

};

main() {

 dyn_temp local_x[3]={dyn_temp("something")};

 printf("%s\n",local_x[2].name);

}
--------------------------------------------------------------------------
1D Program output using GNU compilers:
==========================================================================
something
nothing
nothing
nothing
==========================================================================
--------------------------------------------------------------------------
1D Program output using SUN's compiler:
==========================================================================
something
nothing
nothing
nothing
=========================================================================
-------------------------------------------------------------------------

No problems so far - the problems show up for the 2D array:

Example program for 2D aray:
-------------------------------------------------------------------------
/* 
 * A test file for partially initialized 2D arrays of objects
 * The constructors for the class print out a member variable "name"
 * as they (the constructors) are called. The program then prints the
member
 * variable "name" for one of the uninitialized array elements. The
default
 * constructor should be called N*N-1 (N is 3 in the example below) times.
 */

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

class dyn_temp {
public:

 char name[100];

 dyn_temp(char *name_in) {
	strcpy(name,name_in);
	printf("%s\n",name);
 }
 dyn_temp() {
	strcpy(name,"nothing");
	printf("%s\n",name);
 }

};

main() {

 dyn_temp local_x[3][3]={dyn_temp("something")};

 printf("%s\n",local_x[2][2].name);

}
-------------------------------------------------------------------------
2D Program output using GNU compilers:
=========================================================================
something

=========================================================================
2D Program output using SUN's compiler:
=========================================================================
something
nothing
nothing
nothing
nothing
nothing
nothing
nothing
nothing
nothing
=========================================================================


Sorry for the length of this message.
Please let me know if you agree or disagree that this is an example of
non-compliance.

Thanks for your efforts!

Regards,
Darel Linebarger
Professor in Electrical Engineering
The University of Texas at Dallas




More information about the Gcc-bugs mailing list