将结果存储在变量中会产生奇怪的结果

时间:2016-04-06 03:12:20

标签: c fat32 fat

我有一段代码有时会产生正确的结果。唯一的区别是我将结果存储在一个中间变量中。

整体功能签名是:

payload not in testlist

这有效:

FS_FATEntry getFATEntryForCluster(FS_Cluster cluster, FS_Instance * fsi)

这不是:(请注意,FS_FATEntry的类型定义为switch (fsi->type) { case FS_FAT12: if (cluster % 2) return ((*((uint16_t *)&FATSector[entOffset])) >> 4); else return ((*((uint16_t *)&FATSector[entOffset])) & 0x0FFF); case FS_FAT16: return (*((uint16_t *)&FATSector[entOffset])); case FS_FAT32: return ((*((uint32_t *)&FATSector[entOffset])) & 0x0FFFFFFF); }

uint32_t

当运行第二段代码时,这是我得到的输出的片段:

FS_FATEntry entry = 0xFFFFFFFF;
switch (fsi->type) {
    case FS_FAT12:
        if (cluster % 2)
            entry = ((*((uint16_t *)&FATSector[entOffset])) >> 4);
        else
            entry = ((*((uint16_t *)&FATSector[entOffset])) & 0x0FFF);
    case FS_FAT16:
        entry = (*((uint16_t *)&FATSector[entOffset]));
    case FS_FAT32:
        entry = ((*((uint32_t *)&FATSector[entOffset])) & 0x0FFFFFFF);
}
free(FATSector);
printf("Cluster %04X : %04X Entry\n", cluster, entry);
return entry;

1 个答案:

答案 0 :(得分:3)

原始代码从每种情况返回,新代码通过......你是否打算在开关上掉头,即不使用break?