[cfe-dev] -Wcast-align and #pragma pack

Sean McBride sean at rogue-research.com
Tue Feb 8 17:19:21 PST 2011


Hi all,

Consider this C code:

--------
#include <Carbon/Carbon.h>

int main(void)
{
	FSCatalogInfo catalogInfo = {};
	FileInfo* fileInfo = (FileInfo*)(&catalogInfo.finderInfo);
	(void)fileInfo;
	
	return 0;
}
--------

With -Wcast-align clang says:

test.c:6:23: warning: cast from 'UInt8 (*)[16]' to 'FileInfo *' (aka
'struct FileInfo *')
      increases required alignment from 1 to 2 [-Wcast-align]
        FileInfo* fileInfo = (FileInfo*)(&catalogInfo.finderInfo);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm wondering two things:

a) could/would/will this be an actual problem?  The docs for the
FSCatalogInfo struct even say:

  /*
   * kFSCatInfoFinderInfo / file type, creator, flags, location. 
   * Coerce to a File/FolderInfo to use.
   */
  UInt8               finderInfo[16];


b) Files.h starts with #pragma pack(push, 2).  Does that make the
warning a false positive?

Thanks,

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada






More information about the cfe-dev mailing list