Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 14, 2004 variables of type void & optional members | ||||
---|---|---|---|---|
| ||||
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 Re: variables of type void & optional members | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Zaitseff | 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 Re: variables of type void & optional members | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 Re: variables of type void & optional members | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Zaitseff | 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 |
Copyright © 1999-2021 by the D Language Foundation