# GCC/Cygwin and long longs. A bug?

This topic is 4699 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Lo, I'm currently coding a sign extension function (and messing around with long long's a lot, since I'm working on a 32-bit platform). I believe my sign extension function works correctly - but GCC is really weird when it comes to printing them. For example, here's my sign extension function (QWORD is an unsigned long long)
QWORD SignExtend(QWORD value,DWORD highBit)
{
if (((value >> highBit) & 1) == 1)
{
/* Set all bits higher than highBit to one */
DWORD i=highBit+1;
while (i < 32)
value|=(1 << i++);

value|=(0xFFFFFFFFULL << 32);
printf("%#llX\n",value);
}

return value;
}


In theory, this should print a value above 4 billion (i.e. > 0xFFFFFFFF) but all that gets printed are the lower 32 bits. The GCC version I'm using is 3.4.4. What is wrong? I've also found general weirdness with printing long longs. For instance, I print one, and the next long long printed is zero. If I print them seperately, there's no problem. Should I submit a bug to the cygwin mailing list or gcc mailing list? Also, I'm currently compiling with -mno-cygwin. I don't know if that changes much. CloudNine [Edited by - CloudNine on January 3, 2006 5:50:43 AM]

##### Share on other sites
That's weird..

Have you tried moving the ll type to the other side of the # modifier (it's supposed to and a 0x prefix to hexadecimal constants, right?), or removing it entirely? You may even want to check if it works for regular decimal values (%lld).
Have you tried sanity-checking GCC's printf type checker by sending a regular integer instead of a 64-bit one?

Otherwise you may just have to do a bit of digging in the source to find out what's happening, although you'd think something as basic as this should've been properly tested.

##### Share on other sites
Yep, I've tried everything, and have -Wall on so printf arguments are checked. But no luck. It still prints out as if the argument were 32 bits.

I'll have to post to the cygiwn mailing list then?

##### Share on other sites
Quote:
 Original post by CloudNineI'll have to post to the cygiwn mailing list then?
Well, either that or step through it in a debugger.
Of course you may want to check other versions and distributions of GCC too, possibly even check out the official bug list to see if it's a known issue.

Quote:
 0xFFFFFFFFULL
Cute..

##### Share on other sites
Tried it using gcc 3.3.4 for linux (using libc 2.3.4) and it performs correctly. I'm now assuming it's something wrong with the cygwin c library. I can't find the package for it in setup.exe, I'll search harder :)

##### Share on other sites
This is a long standing problem with cygwin and long longs.

Essentially, long long is a gnu extension. It is present in the compiler, so the code compiles correctly, but long long is not present in the c standard library you are using, probably because it is the M$C-runtime. Try using "%I64X" or such MS-specific int64 extension instead of gnu-specific "%llX" #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by CloudNineTried it using gcc 3.3.4 for linux (using libc 2.3.4) and it performs correctly. I'm now assuming it's something wrong with the cygwin c library. I can't find the package for it in setup.exe, I'll search harder :) Quote:  Original post by CloudNineAlso, I'm currently compiling with -mno-cygwin. I don't know if that changes much. I just noticed that you're compiling in the mingw "mode", which IIRC uses Microsoft's CRT directly instead of GNU's implementation. And since VC doesn't support C99 long longs you'll probably have to use "%I64X" instead. edit: Beaten.. #### Share this post ##### Link to post ##### Share on other sites Ah, that solves it. Sorry to trouble you guys. gcc still complains about that format specifier tho, but it works :) #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by etothexEssentially, long long is a gnu extension. It is present in the compiler, so the code compiles correctly, but long long is not present in the c standard library you are using, probably because it is the M$ C-runtime.

AFAIK, (unsigned) long long is standard C99.

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633312
• Total Posts
3011312
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!