www.digitalmars.com         C & C++   DMDScript  

D - Anonimous structs and unions

reply Dario <Dario_member pathlink.com> writes:
Why don't anonimous structs and unions work if written in a function scope? This
would be useful for specifying the stack frame's layout.
For example:
uint func(float a)
{
union
{
uint b;
float c;
}
c = a;
return b;
}
Jul 11 2003
parent reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
You can work around by using a named struct or union, no?

But yes, this should be consistent.

But to avoid the copy, perhaps the good old pointer cast might be better.

Sean

"Dario" <Dario_member pathlink.com> wrote in message
news:benefa$2kas$1 digitaldaemon.com...
 Why don't anonimous structs and unions work if written in a function
scope? This
 would be useful for specifying the stack frame's layout.
 For example:
 uint func(float a)
 {
 union
 {
 uint b;
 float c;
 }
 c = a;
 return b;
 }
Jul 12 2003
parent Dario <Dario_member pathlink.com> writes:
You can work around by using a named struct or union, no?

But yes, this should be consistent.

But to avoid the copy, perhaps the good old pointer cast might be better.
Yes you're right. I only wanted to show what I meant: I wasn't able to think of a better example. :-)
Sean
Jul 12 2003