あなたはこれをインライン化することができ、static
とC.組み合わせで全体の構造体を返すことができ、あまりにも
static build_field compose_field(unsigned char uc)
{
union {
unsigned char uc;
build_field bf;
} uni = {uc};
return uni.bf;
}
(GCCで-O1から始まります)
使用
int main(void)
{
build_field val;
val = compose_field(0xa5); // "constructor"
printf(" {%u %u %u %u}\n"
, (unsigned int) val.build
, (unsigned int) val.ability
, (unsigned int) val.hability
, (unsigned int) val.shinyness
);
return 0;
}
-O2と
GCC出力:非定数引数で
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $1, 20(%esp)
movl $0, 16(%esp)
movl $1, 12(%esp)
movl $5, 8(%esp)
movl $.LC0, 4(%esp)
movl $1, (%esp)
call __printf_chk
xorl %eax, %eax
leave
ret
:(uc = 0xa5 * random();
):
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
call random
movl $-91, %ecx
xorl %edx, %edx
movl $.LC0, 4(%esp)
movl $1, (%esp)
imull %ecx, %eax
movb %al, %dl
movl %edx, %eax
shrl $7, %eax
movl %eax, 20(%esp)
movl %edx, %eax
shrl $6, %eax
andl $1, %eax
movl %eax, 16(%esp)
movl %edx, %eax
andl $31, %edx
shrl $5, %eax
andl $1, %eax
movl %eax, 12(%esp)
movl %edx, 8(%esp)
call __printf_chk
xorl %eax, %eax
leave
ret
'U8ヴァル= 0xb5。 build = val & 0x1f;能力=(val&0x20)>> 5; hability =(val&0x40)>> 6; shinyness =(val&0x80)>> 7;またはビットを入れたい序列。 – pmg