Enabling long long in C89 at GCC 3.2, 4.4 and 5.4

305 views Asked by At

I'm working in C89 in quite a restricted environment. I am required to write for a compiler based on GCC 4.4, but my code must also pass tests compiled with GCC 3.2. Our everyday development compiler is GCC 5.4. For my money, this is as mad as it sounds, but those are the cards I've been dealt.

Because we require 64-bit integers, we have taken the step of relaxing the C89 rules in order to use long long. Our initial code deals with the problem like this:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wlong-long"
typedef unsigned long long my_type
#pragma GCC diagnostic pop

Unfortunately, this wouldn't work with GCC 4.4, because the push and pop operations were introduced in GCC 4.6, so I changed it to:

#pragma GCC diagnostic ignored "-Wlong-long"
typedef unsigned long long my_type
#pragma GCC diagnostic error "-Wlong-long"

Alas, GCC 3.2 doesn't like it:

warning: ignoring #pragma GCC diagnostic
ISO C89 does not support `long long'
warning: ignoring #pragma GCC diagnostic

Seeing that it's compiled with -Wunknown-pragmas, I suspect that #pragma GCC diagnostic didn't exist at the time of GCC 3.2's release.

Can anyone suggest a solution, please?

1

There are 1 answers

0
mevets On

If you need c89 for a reason, trying to subvert that by weird compiler hacks isn't likely in anyones best interest. You can define your type:

typedef struct { unsigned _[2]; } my_type;

Then write the appropriate operations in either C or asm, such as:

my_type MyAdd(my_type a, my_type b);
my_type MySub(my_type a, my_type b);
...

Someday, if you are permitted a newer edition of C, it is an easy upgrade.