Click here to Skip to main content
15,889,462 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
AnswerRe: Which code you suggest? Pin
TheGreatAndPowerfulOz30-Jul-13 10:18
TheGreatAndPowerfulOz30-Jul-13 10:18 
AnswerRe: Which code you suggest? Pin
johannesnestler1-Aug-13 4:04
johannesnestler1-Aug-13 4:04 
AnswerRe: Which code you suggest? Pin
Vasudevan Deepak Kumar2-Aug-13 8:29
Vasudevan Deepak Kumar2-Aug-13 8:29 
GeneralMisaligned elephants Pin
Matthew Faithfull22-Jul-13 2:10
Matthew Faithfull22-Jul-13 2:10 
GeneralRe: Misaligned elephants Pin
Richard Deeming22-Jul-13 11:34
mveRichard Deeming22-Jul-13 11:34 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull22-Jul-13 11:54
Matthew Faithfull22-Jul-13 11:54 
GeneralRe: Misaligned elephants Pin
ExcellentOrg22-Jul-13 21:25
ExcellentOrg22-Jul-13 21:25 
GeneralRe: Misaligned elephants Pin
enhzflep23-Jul-13 19:51
enhzflep23-Jul-13 19:51 
I'm more than a little curious as to which compilers you're working with, given that #pragma pack works for both VC and GCC, albeit with slightly different syntax.

I'm not in a position to test VC just now, but couldn't you simply add to wrap each of the compiler-specific packing semantics, in much the same way as programs designed to compile under vc, mingw and *nix gcc?

I'd be tempted to use something like the following (Can't remember and too lazy to check compiler defines, hence the manual compiler specification)

C++
#define mingw 1
//#define msvc 1


#ifdef mingw
    #pragma pack(push,1)
#endif

#ifdef msvc
    #pragma pack (1)
#endif
typedef struct tagBITMAPFILEHEADER {
	WORD	bfType;
	DWORD	bfSize;
	WORD	bfReserved1;
	WORD	bfReserved2;
	DWORD	bfOffBits;
} BITMAPFILEHEADER,*LPBITMAPFILEHEADER,*PBITMAPFILEHEADER;
#ifdef mingw
    #pragma pack(pop)
#endif

#ifdef msvc
    #pragma pack()
#endif // VC

Make it work. Then do it better - Andrei Straut

GeneralRe: Misaligned elephants Pin
Matthew Faithfull23-Jul-13 23:03
Matthew Faithfull23-Jul-13 23:03 
GeneralRe: Misaligned elephants Pin
enhzflep23-Jul-13 23:39
enhzflep23-Jul-13 23:39 
GeneralRe: Misaligned elephants Pin
Sentenryu24-Jul-13 0:38
Sentenryu24-Jul-13 0:38 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull24-Jul-13 0:55
Matthew Faithfull24-Jul-13 0:55 
GeneralRe: Misaligned elephants Pin
Sentenryu24-Jul-13 1:18
Sentenryu24-Jul-13 1:18 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull24-Jul-13 1:23
Matthew Faithfull24-Jul-13 1:23 
GeneralRe: Misaligned elephants Pin
RafagaX24-Jul-13 4:41
professionalRafagaX24-Jul-13 4:41 
GeneralRe: Misaligned elephants Pin
Sentenryu24-Jul-13 6:08
Sentenryu24-Jul-13 6:08 
GeneralRe: Misaligned elephants Pin
BiggerDon24-Jul-13 2:15
BiggerDon24-Jul-13 2:15 
GeneralRe: Misaligned elephants Pin
Gary Wheeler24-Jul-13 0:13
Gary Wheeler24-Jul-13 0:13 
GeneralRe: Misaligned elephants Pin
YvesDaoust23-Jul-13 22:51
YvesDaoust23-Jul-13 22:51 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull23-Jul-13 23:10
Matthew Faithfull23-Jul-13 23:10 
GeneralRe: Misaligned elephants Pin
Ralph Little24-Jul-13 6:32
Ralph Little24-Jul-13 6:32 
GeneralRe: Misaligned elephants Pin
Member 460889824-Jul-13 10:02
Member 460889824-Jul-13 10:02 
GeneralRe: Misaligned elephants Pin
SortaCore24-Jul-13 0:04
SortaCore24-Jul-13 0:04 
GeneralRe: Misaligned elephants Pin
rbocquier24-Jul-13 0:39
rbocquier24-Jul-13 0:39 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull24-Jul-13 0:53
Matthew Faithfull24-Jul-13 0:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.