mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Lounge

Reply
 
Thread Tools
Old 2013-02-23, 02:02   #1
davar55
 
davar55's Avatar
 
May 2004
New York City

5·7·112 Posts
Default very long int

I noted recently in the forum someone referred to
the integer type "long long". Does this refer to
an integer type with 64 bits? Or perhaps 128?
I doubt that my c5.5.1 compiler supports it, and my
test trial failed to get past the declaration.

I once thought the adverbal phrase "very long" would be
used to get a 64 bit type, and "very very long" 128.
Same basic idea. I'd love to get a 64 bit integer from
my compiler, to match the w8 x64 hw.
davar55 is offline   Reply With Quote
Old 2013-02-23, 02:21   #2
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by davar55 View Post
I noted recently in the forum someone referred to
the integer type "long long". Does this refer to
an integer type with 64 bits? Or perhaps 128?
I doubt that my c5.5.1 compiler supports it, and my
test trial failed to get past the declaration.

I once thought the adverbal phrase "very long" would be
used to get a 64 bit type, and "very very long" 128.
Same basic idea. I'd love to get a 64 bit integer from
my compiler, to match the w8 x64 hw.
http://en.wikipedia.org/wiki/Integer...ral_data_types shows it to be 64 bits
science_man_88 is offline   Reply With Quote
Old 2013-02-23, 05:12   #3
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3·29·83 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Dear lord that is wrong -- the meaning of "long" varies from language to language, and in C their size is "implementation defined". So for me on GNU-Linux, an int is 32 bits while a long is 64, however on Windows (at least Visual Studio) an int and long are both 32 bits. Davar will simply have to experiment (or otherwise research) what size a long long is for him.

Code:
#include <stdio.h>

int main(void) {
  printf("a long long has %d bytes\n", sizeof(long long int));
  return 0;
}
Dubslow is offline   Reply With Quote
Old 2013-02-23, 12:18   #4
davar55
 
davar55's Avatar
 
May 2004
New York City

102138 Posts
Default

Thanks. I can't compile that code, it gives the "error"
"Too many types in declaration."
The Borland c5.5.1 is an older compiler and I'm not sure
whether it can generate 64 bit object code
Perhaps using an argument flag I haven't tried yet.

I earlier tried:

Code:
long long x;
 
void main(void)
{
}
and the compiler errs on the first line, same error.
davar55 is offline   Reply With Quote
Old 2013-02-23, 19:19   #5
Xyzzy
 
Xyzzy's Avatar
 
Aug 2002

100000011110112 Posts
Default

Code:
#include <stdio.h>
#include <limits.h>

int main() {
  printf("Size of Char %d\n", CHAR_BIT);
  printf("Size of Char Max %d\n", CHAR_MAX);
  printf("Size of Char Min %d\n", CHAR_MIN);
  printf("Size of int min %d\n", INT_MIN);
  printf("Size of int max %d\n", INT_MAX);
  printf("Size of long min %ld\n", LONG_MIN);
  printf("Size of long max %ld\n", LONG_MAX);
  printf("Size of short min %d\n", SHRT_MIN);
  printf("Size of short max %d\n", SHRT_MAX);
  printf("Size of unsigned char %u\n", UCHAR_MAX);
  printf("Size of unsigned long %lu\n", ULONG_MAX);
  printf("Size of unsigned int %u\n", UINT_MAX);
  printf("Size of unsigned short %u\n", USHRT_MAX);
  return 0;
}
Xyzzy is offline   Reply With Quote
Old 2013-02-23, 19:52   #6
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

722110 Posts
Default

According to Wikipedia, long long is new to C99. It must be an incredibly old compiler, or there might be an option to compile to C99 standards instead of the original ANSI C.
Dubslow is offline   Reply With Quote
Old 2013-02-23, 20:22   #7
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
Rep├║blica de California

2·73·17 Posts
Default

When I was first learning C I found the lack of unambiguous data typing (analogous to Fortran-style 'integer*4') to be an appalling piece of stupidity. Since we are still stuck with it, I can only surmise that the folks that populate the C-related standards boards secretly enjoy such arcana.

Solution now is just as then: put together a header file containing the needed typedefs for the various platforms of interest to you, such that your code using said typedefs only shows the resulting unambiguous type, e.g. uint64. Write a small "on program start" test utility which checks the lengths and any other key type attributes (e.g. floating point ranges) at runtime.
ewmayer is offline   Reply With Quote
Old 2013-02-23, 20:29   #8
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

722110 Posts
Default

I read that the ill defined sizes were so that if you, say, wanted to write a C compiler on some something with like a few kilobytes of memory total, you (the implementation creator) could implement the types to be smaller than usual, right at the lower limit of the possible size range so that you would have to rewrite existing code (i.e. change to smaller types) as little as possible (any code that runs on such a device probably wouldn't rely on an int being 32 bits, since that's an unusual requirement [this forum being an exception]).

tl;dr extreme portability.
Dubslow is offline   Reply With Quote
Old 2013-02-23, 20:49   #9
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

132×59 Posts
Default

Quote:
Originally Posted by ewmayer View Post
When I was first learning C I found the lack of unambiguous data typing (analogous to Fortran-style 'integer*4') to be an appalling piece of stupidity. Since we are still stuck with it, I can only surmise that the folks that populate the C-related standards boards secretly enjoy such arcana.
As has been said many times before, both here and elsewhere...

"C -- All the power, and all the safety features, of a chain saw...."
chalsall is online now   Reply With Quote
Old 2013-02-23, 20:59   #10
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
Rep├║blica de California

2·73·17 Posts
Default

Quote:
Originally Posted by Dubslow View Post
I read that the ill defined sizes were so that if you, say, wanted to write a C compiler on some something with like a few kilobytes of memory total, you (the implementation creator) could implement the types to be smaller than usual, right at the lower limit of the possible size range so that you would have to rewrite existing code (i.e. change to smaller types) as little as possible (any code that runs on such a device probably wouldn't rely on an int being 32 bits, since that's an unusual requirement [this forum being an exception]).
Which was of very great importance ... 30-40 years ago. Fortran-90 solved this in a more modern fashion via typedef foo_t = "get type of at least this size and precision" functionality.

Quote:
tl;dr extreme portability.
I don't consider having to write custom header files and then deal with the inevitable bugs/crashes resulting from the inevitable hidden size assumptions which creep into one's code as an example of "portability". Allowing me to specify 'integer*4' and be guaranteed that I get just that (or at least that), in a highly visible type-size-encoding fashion ... that's portable.

I stand by my "appalling piece of stupidity" categorization. And it even stupider now than it was then.
ewmayer is offline   Reply With Quote
Old 2013-02-23, 21:04   #11
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default

I agree it's quite dumb for a modern language. I was just trying to lend some perspective. (Keep in mind these choices were made in the 80s, and have been kept for backwards compatibility.)
Dubslow is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How long is too long? ThomRuley Msieve 3 2013-11-30 04:52
How long until annihilation? Zeta-Flux Soap Box 26 2011-10-19 00:51
Using long long's in Mingw with 32-bit Windows XP grandpascorpion Programming 7 2009-10-04 12:13
I think it's gonna be a long, long time panic Hardware 9 2009-09-11 05:11
How long is too long? schickel Lounge 2 2009-02-22 12:31

All times are UTC. The time now is 18:32.


Thu Oct 28 18:32:46 UTC 2021 up 97 days, 13:01, 0 users, load averages: 1.10, 1.25, 1.34

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.