Reformulating code to avoid nasty surprises

GCC emits a warning when a pointer of a certain type is reinterpreted
as something else and assigned. The potential issue is that GCC might
reorder the way the pointer is read/written because it might assume the
wrong type, therefore it is better to avoid such things.
Merge pull request #970 from cduclos/tls-generic-warning

Reformulating code to avoid nasty surprises