Thread overview
variables of type void & optional members
Sep 14, 2004
Ilya Zaitseff
Sep 14, 2004
Russ Lewis
Sep 14, 2004
Sean Kelly
September 14, 2004
Now following not compiles - "variable optional_member voids have no value"

struct Foo(T)
{
  T optional_member;
  int required_member;
}

void main()
{
  alias Foo!(void) Foo1;
}

But why D don't allow void variables when no one use it? If I don't need an optional_member in Foo, why waste space for fictional helper type?
I think, D should give an error, when someone try to _use_ void variable.

Just my opinion, anyway :)
September 14, 2004
if you're trying to do padding in the struct, you can use other types, or
the align() .. thing.

void itself has no size as it has no type.  so what you're trying to do is, well, not just impossible, but counterintuitive.


September 14, 2004
Jarrett Billingsley wrote:
> if you're trying to do padding in the struct, you can use other types, or
> the align() .. thing.
> 
> void itself has no size as it has no type.  so what you're trying to do is,
> well, not just impossible, but counterintuitive.

I got the impression that what he was saying was that, if you used the template parameter 'void', then he wanted the 'optional_member' to be unusable.  This doesn't really fit with the C/C++/Java/D paradigm. However, he can do it with a template specialization:



> struct Foo(T) {
>   T optional_member;
>   int required_member;
> };
>  struct Foo(T : void) {
>   int required_member;
> };
>  import std.c.stdio;
> void main() {
>   alias Foo!(void) Foo1;
>   alias Foo!(int)  Foo2;
>   Foo1 var1;
>   Foo2 var2;
>   printf("%d %d\n", var1.sizeof, var2.sizeof);
> }

September 14, 2004
In article <opseajtwu3aaezs2@ilya.tec.amursk.ru>, Ilya Zaitseff says...
>
>Now following not compiles - "variable optional_member voids have no value"
>
>struct Foo(T)
>{
>   T optional_member;
>   int required_member;
>}
>
>void main()
>{
>   alias Foo!(void) Foo1;
>}

Try this:

# struct Foo(T)
# {
#     T optional_member;
#     int required_member;
# }
#
# struct Foo(T:void)
# {
#     int required_member;
# }


Sean