Tell me if I counted how many bytes are needed for this structure ...

typedef struct _WIN32_FIND_DATA { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[MAX_PATH]; TCHAR cAlternateFileName[14]; } 

4 + ((4 + 4) * 3) + (4 * 4) + 261 + 14 = 319 bytes

  • one
    Not the fact, depends on the added alignment. ru.stackoverflow.com/a/435733/10105 Get better sizeof . - VladD
  • one
    By the way, isn't MAX_PATH 260? - VladD
  • one
    And the size of TCHAR may not be 1. - VladD
  • @VladD so MAX_PATH seems to be 260 without considering the last "0" (end of line), and I counted TCHAR as an array of 14 bytes. - alex-rudenkiy
  • @VladD think for it I was mistaken for only 1: D. sizeof counted 318 bytes, but I can not understand one thing, that is, cFileName stores the name of a long 259 and another symbol "0"? - alex-rudenkiy

1 answer 1

The size of the structure depends on many factors, for example, on the size of TCHAR (1 or 2 depending on the platform), and the alignment inserted between the elements of the structure by the compiler.

Therefore, it is best not to count manually, but to use the sizeof operator.