Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 28th, 2004, 03:44 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use of long long int

Hi,

I posted a question on this in the (wrong) C#2005 forum; if you have experience with the use of long long, pls have a look at following URL: http://p2p.wrox.com/topic.asp?TOPIC_ID=19890

Thanks beforehand,

Juul Vanparijs
Cressida Technology Ltd
Reply With Quote
  #2 (permalink)  
Old September 28th, 2004, 11:48 AM
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I Don't have your compiler/operating system, but I think I can explain stuff like this:

For Z/OS: try printing juulx with with %llX format, and see it gives all of the bytes (it does with Linux gcc).

For Windows: the formats you used for juuld and and juulx probably need to be something like %LLd or %Ld or something; the format that you are using apparently only prints out 32-bit values (the 32 least significants of the variable). What Windows compiler are you using?

Finally, note that the Windows output for juulb is the same as the z/OS, but the bytes are in reverse order (Intel, AMD, etc. CPUs running Windows are little-endian z/OS is apparently running on a CPU with big-endian mode).



Regards,

Dave
Reply With Quote
  #3 (permalink)  
Old September 30th, 2004, 03:51 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Dave,

Thanks for the reply; I tested with adding "ll" to the HEX conversion specification, and on z/OS this works (and this is the most important to me); on Windows it doesn't change a thing. I'm using the BLOODSHED-DEV-C++ v4 development workbench, which includes the Mingw compiler 2.95.2-1.

Juul

Juul Vanparijs
Cressida Technology Ltd
Reply With Quote
  #4 (permalink)  
Old September 30th, 2004, 09:43 AM
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, here's what I ran with gcc on my Windows XP box
Code:
/* Use of 64-bit unsigned ints with gnu cc */

#include <stdio.h>                                    
typedef unsigned long long Long;
int main(void)                                       
{                                                     
   Long juul = 123456789012345678LL;    
   unsigned char *pjuul;                              
   int i;                                             

   printf("sizeof(Long) = %d\n", sizeof (Long));
   printf("juuld: %lld\n",juul);
   printf("juulx: %016llX\n",juul);                     
   pjuul = (char *) &juul;                            
   printf("juulb: ");                                 
   for (i = 0;i < sizeof(Long); i++) printf("%02X",*(pjuul + i));
   printf("\n");                                      
   return 0;
}
Here's what I got:

sizeof(Long) = 8
juuld: 123456789012345678
juulx: 01B69B4BA630F34E
juulb: 4EF330A64B9BB601

This is what I expected.


Regards,

Dave
Reply With Quote
  #5 (permalink)  
Old October 1st, 2004, 02:41 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dave,

Yeah, your results are correct. So it looks like there's some bug, either in Bloodshed, or in MingW, or in Win2000. But as I managed to get it to work on the mainframe (and that's where I really need it), I think I'm going to put this one to sleep. Thanks for your assistance...


Juul Vanparijs
Cressida Technology Ltd
Reply With Quote
  #6 (permalink)  
Old October 2nd, 2004, 10:24 AM
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I finally played around with mingw32, and found that the following works. %I64 is the key (even though the documentation that I could find for dev-cpp seemed to indicate that %ll would work).

Code:
/* Use of 64-bit unsigned ints with mingw32 gcc */

#include <stdio.h>                                    
typedef long long Long;
int main(void)                                       
{                                                     
   long long juul = 123456789012345678LL;    
   unsigned char *pjuul;                              
   int i;                                             

   printf("With dev-cpp mingw32 gcc:\n\n");
   printf("sizeof(Long) = %d\n", sizeof (Long));
   printf("juuld: %I64d\n",juul);
   printf("juulx: %016I64X\n",juul);                  
   pjuul = (char *) &juul;                            
   printf("juulb: ");                                 
   for (i = 0;i < sizeof(juul); i++) printf("%02X",*(pjuul + i));
   printf("\n"); 
   system("pause");                                     
   return 0;
The results are

With dev-cpp mingw32 gcc:

sizeof(Long) = 8
juuld: 123456789012345678
juulx: 01B69B4BA630F34E
juulb: 4EF330A64B9BB601
Reply With Quote
  #7 (permalink)  
Old October 3rd, 2004, 09:51 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Dave,

I tried the I64 format specification, and that indeed works, so I guess there must be somewhere a bug in the Mingw32 compiler.

Anyways, thanks for the assistance, and talk to you on some other occasion...

Juul Vanparijs
Cressida Technology Ltd
Reply With Quote
  #8 (permalink)  
Old October 3rd, 2004, 01:59 PM
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not a bug: a feature with hidden documentation. The thing that made me try %I64 is that Microsift VisualC++ uses %I64 to format long longs. I'm not sure why Mingw32 didn't use %ll, like the other GNU gcc compilers. Oh, well ...

Regards,

Dave
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the difference between an int and a long jnrico C++ Programming 4 March 4th, 2007 01:29 AM
Long Long int to bin walid C# 0 January 23rd, 2007 12:47 PM
Double in Long int walid C# 0 January 20th, 2007 08:50 AM
Use of long long int jvanp C# 2005 2 September 20th, 2006 06:07 PM
Modifying long text in a long field sajsal Classic ASP Databases 1 February 20th, 2004 12:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.