This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

incorrect static char * assumption(?)


egcs-2.91.66 appears to be making an erroneous assumption about the
contents of a static char * within a single printf() call.

SYMPTOM:

	#include <stdio.h>
	#include <string.h>

	char newstring[5];

	int main(void);
	char *output(char *);

	int main()
	{
		printf ("%s %s\n", output("this"), output("that"));
		printf ("%s\n", output("this"));
		printf ("%s\n", output("that"));

		return 0;
	}

	char *output(char *string)
	{
		strcpy(newstring, string);
		return newstring;
	}


Output from the program:

	this this
	this
	that

Obviously the first line of output should read:

	this that

It appears the compiler is making the assumption that because the
function output() returns the same char *, it will contain the same
value for each call WITHIN a single printf() call.  However, it does not
make this assumption BETWEEN printf() calls.

Cheers,
Richard


VERSION:

	gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
	Red Hat 6.1

COMPILER INVOCATION:

	g++ testme.cc -o testme

MACHINE:

	Dell - Intel P133

GCC BUILD OPTIONS:

	Unknown.  Binaries installed from RedHat RPM

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]