作者MaxHaru (懂得放手..才是王道)
看板C_and_CPP
标题[讨论] struct的Initial
时间Tue Apr 12 16:08:57 2016
各位好,
有一个关於struct Initial的问题请教.
假使我现在定义了struct/union如下:
typedef union
{
unsigned short wWord;
struct
{
bByteH;
bByteL;
}byte;
}WordVar;
typedef struct
{
unsigned char a;
unsigned char b;
}_defType;
若要在宣告_defType变数的同时Initial, 已知方法如下
_defType AAA = {12, 34};
假使现在定义struct _defType2如下:
typedef struct
{
unsigned char a;
WordVar abc;
}_defType2;
如此, 有可能在宣告_defType2变数时,针对bByteH, bByteL进行initial吗?
Ex: _defType2 BBB = {12, ???};
PS: 目前已知可以对wWord进行initial(_defType2 BBB = {12, 0x1234};)
PS: Compiler为非C99系统..
谢谢大家.
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.210.106.78
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1460448539.A.7A9.html
1F:→ Schottky: _defType2 BBB = {12, {.byte={1, 0}}}; 04/12 16:35
2F:→ Schottky: 提醒你 WordVar 宣告有两个问题: 你忘了给 bByteH 和 04/12 16:36
3F:→ Schottky: bByteL 资料型态之外,High 在前还是 Low 在前要看硬体 04/12 16:37
4F:→ Schottky: x86 是 low byte 在前才对,这叫 little endian 04/12 16:37
5F:→ MaxHaru: 谢谢S大, 但.byte={1,0};是否在非C99 Compiler不能用呢? 04/13 15:23
※ 编辑: MaxHaru (218.210.106.78), 04/13/2016 15:38:21
6F:→ Schottky: 我在回覆之前就有用gcc无参数(gnu89),ansi,c89都测试过 04/13 15:52
7F:→ Schottky: 它应该是写在 C89/C90 standard 里的,但我手边没有 04/13 15:53
8F:→ Schottky: standard 全文 (要花钱买PDF档) 所以没办法引用给你看 04/13 15:53
9F:→ Schottky: 所以你有发生编译不过的问题? 你的 compiler 是哪一种? 04/13 15:54
10F:→ MaxHaru: 再次感谢S大, 我是使用Keil C, 似乎没办法使用.. 04/13 21:13