digitalmars.D - variables of type void & optional members
- Ilya Zaitseff (14/14) Sep 13 2004 Now following not compiles - "variable optional_member voids have no val...
- Jarrett Billingsley (4/4) Sep 13 2004 if you're trying to do padding in the struct, you can use other types, o...
- Russ Lewis (5/27) Sep 13 2004 I got the impression that what he was saying was that, if you used the
- Sean Kelly (13/23) Sep 13 2004 Try this:
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 :)
Sep 13 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.
Sep 13 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); }
Sep 13 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: Sean
Sep 13 2004