May 23, 2004
>Here's another one to consider. In C++ I've had occasion to require a
>sizeof(void), and had to resort to traits in order to get it. Does anyone see a
>downside with sizeof(void) being legal in D?

Yes, you would gloat too much.


May 23, 2004
or a knife to kill people/animals. should not be allowed.

"Juan C" <Juan_member@pathlink.com> schrieb im Newsbeitrag news:c8osai$2jj6$1@digitaldaemon.com...
> <snip>
> >According to Meyer, Commands should be used to change state, and Queries should be used only to query that state.
> </snip>
>
> Well then I submit that a knife is to cut food, and a fork is to pick up
food
> (with a spoon being a specialized type of fork?). So one should not use a
fork
> to cut pancakes.
>
>


May 23, 2004
Sorry, I forgot to say. I would want sizeof(void) to be 0, so it could function
in constraints
validating type sizes.

"Kris" <someidiot@earthlink.dot.dot.dot.net> wrote in message news:c8oo5n$2dpi$1@digitaldaemon.com...
> I suppose sizeof(void) would need to reflect the size of void[] elements,
> which are 1 byte each ...
>
> "Matthew" <matthew.hat@stlsoft.dot.org>
> > Here's another one to consider. In C++ I've had occasion to require a sizeof(void), and had to resort to traits in order to get it. Does anyone
> see a
> > downside with sizeof(void) being legal in D?
>
>


May 23, 2004
"Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c8p0mt$2pl2$1@digitaldaemon.com...
> Sorry, I forgot to say. I would want sizeof(void) to be 0, so it could
function
> in constraints
> validating type sizes.

There's no way you can make void.sizeof be 0 in D.


May 23, 2004
"Walter" <newshound@digitalmars.com> wrote in message news:c8p9tn$5js$1@digitaldaemon.com...
>
> "Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c8p0mt$2pl2$1@digitaldaemon.com...
> > Sorry, I forgot to say. I would want sizeof(void) to be 0, so it could
> function
> > in constraints
> > validating type sizes.
>
> There's no way you can make void.sizeof be 0 in D.

Do you mean "there's no way that would be a good thing to do" or "there's no way to technically achieve that"?

I can't believe the latter, so am intrigued as to your reasoning for the former.


May 23, 2004
"James McComb" <alan@jamesmccomb.id.au> wrote in message news:c8ophn$2flh$1@digitaldaemon.com...
> If functions that return void and functions that return non-void should be used for fundamentally different purposes, when would it be a good idea to have function template parameterized to sometimes return void and sometimes return non-void?

My thoughts exactly. I know this feature was added to C++, but are there legitimate uses for it, or is it a misfeature, or a workaround for another bug in C++?


May 23, 2004
"Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c8pbkm$7tr$1@digitaldaemon.com...
>
> "Walter" <newshound@digitalmars.com> wrote in message news:c8p9tn$5js$1@digitaldaemon.com...
> >
> > "Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c8p0mt$2pl2$1@digitaldaemon.com...
> > > Sorry, I forgot to say. I would want sizeof(void) to be 0, so it could
> > function
> > > in constraints
> > > validating type sizes.
> >
> > There's no way you can make void.sizeof be 0 in D.
>
> Do you mean "there's no way that would be a good thing to do" or "there's
no way
> to technically achieve that"?
>
> I can't believe the latter, so am intrigued as to your reasoning for the
former.

The reason is because you can do pointer arithmetic on void* and indexing of void[]. An axiom of pointer arithmetic is to advance a void* pointer, you add void.sizeof. Breaking this would make an ugly and confusing wart in the language.


May 23, 2004
Yes, I can certainly see that point.



"Walter" <newshound@digitalmars.com> wrote in message news:c8pgrt$f23$2@digitaldaemon.com...
>
> "Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c8pbkm$7tr$1@digitaldaemon.com...
> >
> > "Walter" <newshound@digitalmars.com> wrote in message news:c8p9tn$5js$1@digitaldaemon.com...
> > >
> > > "Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c8p0mt$2pl2$1@digitaldaemon.com...
> > > > Sorry, I forgot to say. I would want sizeof(void) to be 0, so it could
> > > function
> > > > in constraints
> > > > validating type sizes.
> > >
> > > There's no way you can make void.sizeof be 0 in D.
> >
> > Do you mean "there's no way that would be a good thing to do" or "there's
> no way
> > to technically achieve that"?
> >
> > I can't believe the latter, so am intrigued as to your reasoning for the
> former.
>
> The reason is because you can do pointer arithmetic on void* and indexing of void[]. An axiom of pointer arithmetic is to advance a void* pointer, you add void.sizeof. Breaking this would make an ugly and confusing wart in the language.
>
>


May 23, 2004
Walter wrote:
> "James McComb" <alan@jamesmccomb.id.au> wrote in message
> news:c8ophn$2flh$1@digitaldaemon.com...
> 
>>If functions that return void and functions that return non-void should
>>be used for fundamentally different purposes, when would it be a good
>>idea to have function template parameterized to sometimes return void
>>and sometimes return non-void?
> 
> My thoughts exactly. I know this feature was added to C++, but are there
> legitimate uses for it, or is it a misfeature, or a workaround for another
> bug in C++?

No, it is an important point in the C++ language, cause without it, you'd end up writing a lot of template specialisations for void. Imagine the following very simple example:

class Handler(ReturnType, Parameter)
{
public:
  alias ReturnType function(Parameter) Function;
  this (Function func) { func_ = func; }
  ReturnType opCall (Parameter1 parameter) { return func_ (parameter); }

private:
  Function func_;
};

(Of course, you'll probably also want to have a Handler template for functions with 2, 3, 4, ..., x parameters).

This won't work if ReturnType is void. The only way to get this to work in D (I should note, that I'm using the latest gdc) is to create a void specialisation for every such template class. This leds to lots of code duplication which is IMHO a bad thing. One should also keep in mind, that the above is a very simple example.

Therefore I consider this a vital feature for template programming. The adoption should be easy, just add a paragraph to the spec: "If a function that is declared to return void, discovers a return statement with an expression, this expression has to evaluate to void." or something like that.

best regards,
Benedikt

-- 
NetBSD Operating system:                       http://www.NetBSD.org/
pkgsrc "Work in progress":                  http://pkgsrc-wip.sf.net/
XFce desktop environment:                        http://www.xfce.org/
German Unix-AG Association:                   http://www.unix-ag.org/
os-network:                                 http://www.os-network.de/

OpenPGP Key: http://www.home.unix-ag.org/bmeurer/#gpg
May 23, 2004
D allows lots of stuff that Bertrand Meyer does not like. If you want to follow his coding principles, you are free to do so, but obviously D was not designed to force people using a certain style, but to allow them to express themselves in the way they want to.

I like Bertrand Meyer's ideas, but I think that they are a bit idealistic and lead to extremely wordy programs in real life. Just consider a stack class that offeres a "pop" routine. According to Bertrand Meyer, "pop" would be illegal and you should split it up into "get_top" and "remove_top"...



James McComb wrote:

> Benedikt Meurer wrote:
>> Hello,
>> 
>> Would it be possible to add support for void returns, as in
>> 
>> void f1 () { ... }
>> void f2 () { ...; return f1 (); }
> 
> According to Bertrand Meyer, creator of Eiffel, there are two kinds of
> routines:
>     Commands (i.e. functions that return void), and
>     Queries (i.e. functions that return non-void).
> 
> According to Meyer, Commands should be used to change state, and Queries should be used only to query that state.
> 
> What is the point of this distinction? For a variety of reasons, the
> most important being exception-safety, Queries should not have
> side-effects (roughly, they should not change state). This is why pop()
> doesn't return a value in the STL stack. pop() is the Command, and top()
> is the Query.
> 
> If functions that return void and functions that return non-void should be used for fundamentally different purposes, when would it be a good idea to have function template parameterized to sometimes return void and sometimes return non-void?
> 
> James McComb