Skip to content

Commit

Permalink
Rearrange mmx_t union to make gcc happy.
Browse files Browse the repository at this point in the history
When we initialize with an unsigned long long using:
  mmx_t var = { 0x8000000000000000ULL };
It makes the compiler unhappy because it tries to
assign the mmx_t's .q which is of type long long
and this number is too large to be represented in
a long long. By moving the unsigned long long .uq to
be first in the union the compiler will try that
first and not give a narrowing complaint.
An alternative in C99 code is:
  mmx_t var = { .uq = 0x8000000000000000ULL };
But in C++ the only alternative is:
  mmx_t var;
  var.uq = 0x8000000000000000ULL;
Which to my eyes is less elegant.
  • Loading branch information
daniel-kristjansson committed Dec 13, 2012
1 parent 7c7b44a commit 5a8b3ed
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mythtv/libs/libmythbase/ffmpeg-mmx.h
Expand Up @@ -31,9 +31,14 @@
* values by ULL, lest they be truncated by the compiler)
*/

/* Note: moved uq to be first so we can initialize with ULL
* in C++11 code without narrowing complaints or use of gcc
* extensions. -- Daniel Kristjansson 2012-12-13
*/

typedef union {
long long q; /* Quadword (64-bit) value */
unsigned long long uq; /* Unsigned Quadword */
long long q; /* Quadword (64-bit) value */
int d[2]; /* 2 Doubleword (32-bit) values */
unsigned int ud[2]; /* 2 Unsigned Doubleword */
short w[4]; /* 4 Word (16-bit) values */
Expand Down

0 comments on commit 5a8b3ed

Please sign in to comment.