🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3605

Re: are zero lengthed arrays allowed?

#3605
From: Fergus Henderson
Date: Sun, 30 Jul 1995 18:46
91 lines
3402 bytes
scjones@thor.sdrc.com (Larry Jones) writes:

>ffarance@aol.com (FFarance) writes:
>> [...] However, there has been a revival of
>> interest on zero-length objects.  Doug Gwyn has been leading the
>> charge.  I think he will be proposing them for C9X.
>
>My recollection is different -- I remember the key sticking point being
>that the standard was heavily dependent on the concept of "object" but,
>if you allow objects to have a size of zero, the definition of "object"
>falls apart. 

Why does it fall apart?

>Assuming we could fix that (though I don't recall anyone
>having a concrete suggestion for doing so), we would then have to have
>different terms for "real objects" and "zero-size objects" because they
>have different behaviors in some cases.

I'm not yet convinced that this is really the case; it seems to me
that if there is a difference in behaviours, it is much smaller than
you suggest.

>For example, a zero-size
>object is presumably an lvalue (so you can take it's address), but it's
>never a modifiable lvalue (reguardless of its type)

Why not?

What's wrong with

	struct Empty {} empty1, empty2;
	void foo() {
		empty1 = empty2;
	}

?  GNU C allows this.  I don't see a problem.

>and it has no value

Again, why not?
An object with size zero should have a singleton set of possible values.
That is, there should be exactly one value of type `struct Empty'
or of type `void'.

>(it behaves more like a void expression than an expression of its type).

IMHO, the way `void' is used in ANSI C is very confusing.
Perhaps if the ANSI C committee had known a bit more set theory,
they'd have got it right ;-)

A void expression ought to have a value too.
The following should be legal:

	void x;

(Incidentally, gcc allows this, but I suspect it is a bug - there
is no warning even with -ansi -pedantic.)

The following should also be legal:

	void y = (void) 42;

So should the following:

	void foo();
	void bar() {
		return foo();
	}
	void baz() {
		return (void) 42;
	}

In other words, I think the `void' type (as used in void expressions, e.g.
casts to void and functions with void return values) ought to have been like
the unit type in SML.

>I would note that, despite the committee's insistence on not having zero
>size objects, the current standard does have exactly one case where
>these occur (although it doesn't acknowledge it) -- the "thingy" just
>past the end of an array that you're allowed to point to but not
>reference behaves, as far as I can tell, exactly like a zero-size
>object.

I think that is a categorically different case.

-- 
Fergus Henderson              | Designing grand concepts is fun;
fjh@cs.mu.oz.au               | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh   | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC  8B 3E 0F 01 E7 5D C4 3F
Technical Details
Message-ID: <9521204.23608@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjh
References: <3uo582$8of@snlsu1> <3ur7gi$huu@newsbf02.news.aol.com> <3v88lg$or4@info1.sdrc.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c,comp.std.c++
Path: arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: are zero lengthed arrays allowed?
Message-ID: <9521204.23608@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <3uo582$8of@snlsu1> <3ur7gi$huu@newsbf02.news.aol.com> <3v88lg$or4@info1.sdrc.com>
Date: Sun, 30 Jul 1995 18:46:16 GMT