Thread (8 messages) flat view 8 messages, 3 authors, 2016-06-15

Re: What's cooking in git.git (Dec 2013, #02; Fri, 6)

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:59:26

Possibly related (same subject, not in this thread)

Karsten Blees wrote:
(Besides, __attribute__((aligned)) / __declspec(align) can only
_increase_ the alignment, so aligned(1) would have no effect).
Good catch.
Googling some more, I believe the most protable way to achieve this
via 'compiler settings' is

 #pragma pack(push)
 #pragma pack(4)
 struct hashmap_entry {
   struct hashmap_entry *next;
   unsigned int hash;
 };
 #pragma pack(pop)

This is supported by at least GCC, MSVC and HP (see your link). The
downside is that we cannot use macros (in git-compat-util.h) to emit
#pragmas. But we wouldn't have to, as compilers aren't supposed to
barf on unknown #pragmas.
Technically this can be done using macros:

 #if (gcc)
 #	define BEGIN_PACKED _Pragma("pack(push,4)")
 #	define END_PACKED _Pragma("pack(pop)")
 #elif (msvc)
 #	define BEGIN_PACKED __pragma(pack(push,4))
 #	define END_PACKED __pragma(pack(pop))
 #else
 	/* Just tolerate a little padding. */
 #	define BEGIN_PACKED
 #	define END_PACKED
 #end

Then you can do:

 BEGIN_PACKED
 struct hashmap_entry {
 	...
 };
 END_PACKED

Whether that's nicer or uglier than the alternatives I leave to you.
;-)

Thanks,
Jonathan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help