Bug in Norcroft v5.68?
Dave Higton (281) 668 posts |
Please check that I’m not going mad here… My code is:int i = 0; bool bDone = false; unsigned char uc = 0; char short_name[16] = ""; char long_name[256] = ""; // Clear the directory block offset and directory entry number *DirBlockOffset = 0; *DirEntry = 0; ReadBlock (offset_to_root_dir + *DirBlockOffset, da); print_block_data (*da); printf ("\n%02X %02X\n", ATTR_NON_RESERVED, ATTR_LONG_NAME); for (i = 0, bDone = false; (i < 16) & !bDone; i++) { uc = da->byte[i * 32]; switch (uc) { case 0: printf ("%02X: Finished\n", uc); bDone = true; break; case 0xE5: printf ("%02X: Empty\n", uc); break; default: printf ("%02X: valid\n", uc); // Having found out that it is valid, we need to look // at the attributes to decide how to interpret it uc = da->byte[(i * 32) + 11]; printf ("Attributes: %02X\n", uc); short_name[0] = '\0'; long_name[0] = '\0'; if ((uc & ATTR_NON_RESERVED) == ATTR_LONG_NAME) { printf ("This is a fragment of a long name: %02X %02X\n", uc & ATTR_NON_RESERVED, ATTR_LONG_NAME); } break; } }The output I’m getting is: 3F 0F 44: valid Attributes: 28 This is a fragment of a long name: 3E 0F 41: valid Attributes: 0F This is a fragment of a long name: 3F 0F 42: valid Attributes: 00 This is a fragment of a long name: 3E 0F 41: valid Attributes: 0F This is a fragment of a long name: 3F 0F 52: valid Attributes: 00 This is a fragment of a long name: 3E 0F E5: Empty E5: Empty 00: Finished It isn’t ANDing with 0×3F, it’s ORing with 0×3E – and then it’s finding the result equal to 0×0F! What’s going on? Presumably my first action is to change the optimisation levels to see if that makes any difference? |
Peter van der Vos (95) 115 posts |
First, shouldn’t you use a logic AND in the loop: It looks like you defined ATTR_NON_RESERVED and ATTR_LONG_NAME but it is not in your samplecode. I had substitution going wrong when I used something like:
#define ATTR_NON_RESERVED 0x30+0x07
The printing works but aritmatic can go wrong 15 & 0x30 + 0x07
is not the same as 15 & (0x30 + 0x07)
Solution: use ( ) in the define. Hope this helps, Peter V |
Dave Higton (281) 668 posts |
Rats – caught by the preprocessor… Thanks for your help, Peter, that’s fixed it. |