Click here to Skip to main content
15,791,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code snippet:
typedef struct tagBITMAPFILEHEADER {
  WORD    bfType; 
  DWORD   bfSize; 
  WORD    bfReserved1; 
  WORD    bfReserved2; 
  DWORD   bfOffBits; 
} __attribute__((packed)) BITMAPFILEHEADER; 

I compiled it using VC++2012 and got error message:
1>D:\programs\ATP-3\ATP3MMI\MMI\include\sys-include\Windows32/Structures.h(210): error C2065: 'packed' : undeclared identifier

How come?

What I have tried:

I googled with keywords "packed", "compiler options", "VC++" and found all of them can't help me to figure it.
Updated 5-May-16 0:29am

Because it's a nonstandard extension, used in GCC.
For VS, you want #pragma pack[^]
Share this answer
Stan Huang 5-May-16 6:27am    
I added
#pragma pack( 1 )
in the beginning of the file, but I still got error message:
1>D:\programs\ATP-3\ATP3MMI\MMI\include\sys-include\Windows32/Structures.h(214): error C2065: 'packed' : undeclared identifier
OriginalGriff 5-May-16 7:31am    
Yes, because you didn't remove the nonstandard extension...
With the Microsoft C++ compiler, the way to go is the pragma pack[^].
Share this answer
Stan Huang 5-May-16 6:35am    
Do you mean
#pragma pack[^]
I got the following error, VC++ doesn't accept it.
1>D:\programs\ATP-3\ATP3MMI\MMI\include\sys-include\Windows32/Structures.h(33): warning C4081: expected '('; found '['
CPallini 5-May-16 7:27am    
There is a code sample in the linked page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900