Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site burl.UUCP
Path: utzoo!linus!philabs!seismo!harpo!floyd!vax135!ariel!houti!hogpc!houxm!hocda!spanky!burl!rcj
From: rcj@burl.UUCP
Newsgroups: net.lang.c
Subject: interesting C allocation phenomenon (followup)
Message-ID: <207@burl.UUCP>
Date: Mon, 20-Jun-83 10:26:54 EDT
Article-I.D.: burl.207
Posted: Mon Jun 20 10:26:54 1983
Date-Received: Thu, 23-Jun-83 22:34:25 EDT
Organization: Western Electric, Burlington, NC
Lines: 57

It was mentioned that there is a problem with overlays of character
strings which have no dimension given.  The example below was cited:
-------------------------------------------------------------------
main() {
	char s[];
	int i;

	i = 0x12345678;
	s[0] = 'a';

	printf("i = 0x%08x\n",i);
}
--------------------------------------------------------------------

I am running USG 5.0 on a Vax 11/780.  Using sdb, I found the following
allocations:

s	0x7ffff278
i	0x7ffff274

Clearly, there is not conflict here.  Then I tried this declarations
section instead:

	char s[],t[];
	int i;

This yielded:

s	0x7ffff278
t	0x7ffff278
i	0x7ffff274

Again, i was safe from harm, but t was overwritten by s (or vice versa).
My last fling was:

	char s[];
	int i;
	char t[];

This gave the horrifying result of:

s	0x7ffff278
i	0x7ffff274
t	0x7ffff274

i was overwritten by t this time!!!

I can see a hazy pattern emerging here -- does anyone want to clarify
it for me?  I would be most appreciative.  Unless you are sure that it
will be of general interest, you may wish to stick to mail to keep netnews
traffic down.

Thanks 4 ur time,
-- 

The MAD Programmer -- 919-228-3814 (Cornet 291)
alias: Curtis Jackson	...![ floyd sb1 mhuxv ]!burl!rcj