当前位置: 代码迷 >> 综合 >> 结构体,联合体,枚举.sprintf ,结构体变量和指针成员,-含义
  详细解决方案

结构体,联合体,枚举.sprintf ,结构体变量和指针成员,-含义

热度:90   发布时间:2023-12-08 20:26:44.0

typedef struct _LIST_ENTRY {
    struct _LIST_ENTRY  * Flink;
 int a;
    struct _LIST_ENTRY  * Blink;
} LIST_ENTRY,*PLIST_ENTRY;

EX_ListHead是一个_LIST_ENTRY结构体变量,那么EX_ListHead.Flink和EX_ListHead.Flink->Blink代表什么?

答:EX_ListHead.Flink和代表一个_LIST_ENTRY类型的指针,这个指针站4个字节位于EX_ListHead变量的空间内,

EX_ListHead.Flink->Blink,如果令EX_ListHead.Flink=X, 那么EX_ListHead.Flink->Blink相当于X.Blink

sprintf(pstudent[i].name,"Student%d",i+1);

// stores a cylinder/head/sector based ATA address
typedef struct _CHSAddr {
    WORD cylinder;
    WORD head;
    WORD sector;
} CHSAddr, *PCHSAddr;

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// stores a Logical Block Address
typedef DWORD LBAAddr, *PLBAAddr;

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
typedef enum { CHS, LBA } CHSLBA ;

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// stores a union of LBA and CHS address
typedef struct _Addr {
    CHSLBA type;
    union {
        LBAAddr lba;
        CHSAddr chs;
    };
} Addr, *PAddr;

 ///

//调用

 Addr startAddr;

startAddr = LBAtoCHS(&g_FlashInfo, startAddr);

///

static Addr LBAtoCHS(FlashInfo *pFlashInfo, Addr lba)
{
    if(lba.type == CHS)
        return lba;

    Addr chs;
    DWORD tmp = pFlashInfo->dwNumBlocks * pFlashInfo->wSectorsPerBlock;

    chs.type = CHS;
    chs.chs.cylinder = (WORD)(lba.lba / tmp);
    tmp = lba.lba % tmp;
    chs.chs.head = (WORD)(tmp / pFlashInfo->wSectorsPerBlock);
    chs.chs.sector = (WORD)((tmp % pFlashInfo->wSectorsPerBlock) + 1);

    return chs;
}

 

///

  相关解决方案