By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How widely supported is variable type 'long long int' ?

P: n/a
I maintain/enhance some inherited FOSS software in C which has
compiler options for quite a few different Unix-like operating
systems, many of which I've never even heard of.

It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.

Thanks for your help.

Regards,
Charles Sullivan

Jun 22 '07 #1
Share this Question
Share on Google+
21 Replies


P: n/a
On Jun 22, 2:55 pm, Charles Sullivan <cwsul...@triad.rr.comwrote:
I maintain/enhance some inherited FOSS software in C which has
compiler options for quite a few different Unix-like operating
systems, many of which I've never even heard of.

It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.
The long long type was officially introduced with the 1999 Standard,
hence no mention of it in K&R2 which was published 10 years earlier.
A number of compilers recognized and supported the type well before
the new Standard was published, the "long long" name was selected
based on consideration of this fact. While most compilers don't
implement all of C99, a good many of those released in the last 10
years do support long long. Some compilers may require an option to
be set to enable support for long long so keep this in mind. As for
whether it is widely enough supported for your needs, it would be a
good idea to review the compilers you currently support and see if any
of them don't support this type and go from there.

Robert Gamble

Jun 22 '07 #2

P: n/a
Charles Sullivan <cw******@triad.rr.comwrites:
I maintain/enhance some inherited FOSS software in C which has
compiler options for quite a few different Unix-like operating
systems, many of which I've never even heard of.

It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.
The types "long long" and "unsigned long long" were introduced in the
ISO C standard of 1999. That standard is not yet widely implemented,
though pieces of it are.

Many, perhaps most, compilers support long long as an extension, but a
compiler invoked in strict C90 mode will reject long long, even if it
would accept it in a more relaxed mode.

Why do you need "long long"? I suspect what you really need is a
64-bit integer type; long long is guaranteed (in C99) to be at least
64 bits, but it's entirely possible for long to be 64 bits in either
C90 or C99.

I think that some compilers may provide 64-bit integer types, but
without using the name "long long" (Microsoft?).

You might consider defining your own types, perhaps "long_long" and
"unsigned_long_long", in an application-specific header; these would
be typedefs for long long and unsigned long long where they're
available, and for whatever other type is appropriate where they're
not. You should be able to detect whether long long exists by
checking "#ifdef LLONG_MAX" (after #include <limits.h>).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 22 '07 #3

P: n/a
Charles Sullivan wrote:
>
.... snip ...
>
It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.
Long long was introduced with C99. If you don't have a C99
compliant compiler (and you probably don't) they won't work. They
may be available on other systems as extensions, but will not be
portable.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com

Jun 22 '07 #4

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Charles Sullivan wrote:
>>
... snip ...
>>
It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.

Long long was introduced with C99. If you don't have a C99
compliant compiler (and you probably don't) they won't work.
Not true. I have a compiler that isn't C99 compliant, and it supports
"long long" just fine (if I don't invoke it in strict C90 mode).

If you do have a C99 compiler, long long will work.

It does not follow from this that if you don't have a C99 compiler,
long long won't work.
They may be available on other systems as extensions, but will not
be portable.
Exactly. And in fact, "long long" is one of the most common
extensions; I know of very few current C compilers that don't support
it. It's not 100% portable, though; it's up to the OP to decide
whether it's portable *enough*.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 22 '07 #5

P: n/a
Keith Thompson wrote:
>
You might consider defining your own types, perhaps "long_long" and
"unsigned_long_long", in an application-specific header; these would
be typedefs for long long and unsigned long long where they're
available, and for whatever other type is appropriate where they're
not. You should be able to detect whether long long exists by
checking "#ifdef LLONG_MAX" (after #include <limits.h>).
Wouldn't it be better just to use the standard int64_t and uint64_t type
names?

--
Ian Collins.
Jun 22 '07 #6

P: n/a
On Jun 22, 11:55 am, Charles Sullivan <cwsul...@triad.rr.comwrote:
I maintain/enhance some inherited FOSS software in C which has
compiler options for quite a few different Unix-like operating
systems, many of which I've never even heard of.

It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.
Older Microsoft compilers and the OpenVMS C and C++ compilers use:
__int64 and unsigned __int64

The current Microsoft compiler and recent GCC versions accept long
long just fine.

However, you can still run into speedbumps today. Some older, still
running platforms do not have long long (e.g. OpenVMS VAX).

Jun 23 '07 #7

P: n/a
Ian Collins <ia******@hotmail.comwrites:
Keith Thompson wrote:
>You might consider defining your own types, perhaps "long_long" and
"unsigned_long_long", in an application-specific header; these would
be typedefs for long long and unsigned long long where they're
available, and for whatever other type is appropriate where they're
not. You should be able to detect whether long long exists by
checking "#ifdef LLONG_MAX" (after #include <limits.h>).
Wouldn't it be better just to use the standard int64_t and uint64_t type
names?
Probably, depending on what you need them for.

If you need types that are exactly 64 bits wide, then yes, it makes
sense to use int64_t and uint64_t (from <inttypes.hif it exists, or
defining them yourself if they don't).

I think you're assuming that when the OP says "I need long long", he
really means "I need a type that's exactly 64 bits wide". That
assumption is likely to be correct (I've never heard of a C compiler
where long long is anything other than exactly 64 bits) -- but that's
not what "long long" means.

Actually, I think the OP is dealing with some existing code that
depends on long long. The appropriate course of action, particularly
for implementations that don't support long long, probably depends on
just how the code uses it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 23 '07 #8

P: n/a
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
>Charles Sullivan wrote:
>>>
... snip ...
>>>
It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.

Long long was introduced with C99. If you don't have a C99
compliant compiler (and you probably don't) they won't work.

Not true. I have a compiler that isn't C99 compliant, and it
supports "long long" just fine (if I don't invoke it in strict
C90 mode).
You have a C90 compiler with enabled extensions.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 23 '07 #9

P: n/a
Ian Collins wrote:
Keith Thompson wrote:
>>
You might consider defining your own types, perhaps "long_long"
and "unsigned_long_long", in an application-specific header;
these would be typedefs for long long and unsigned long long
where they're available, and for whatever other type is
appropriate where they're not. You should be able to detect
whether long long exists by checking "#ifdef LLONG_MAX" (after
#include <limits.h>).

Wouldn't it be better just to use the standard int64_t and
uint64_t type names?
They don't exist in C90. They may not exist in C99.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 23 '07 #10

P: n/a
CBFalconer wrote:
Ian Collins wrote:
>Keith Thompson wrote:
>>You might consider defining your own types, perhaps "long_long"
and "unsigned_long_long", in an application-specific header;
these would be typedefs for long long and unsigned long long
where they're available, and for whatever other type is
appropriate where they're not. You should be able to detect
whether long long exists by checking "#ifdef LLONG_MAX" (after
#include <limits.h>).
Wouldn't it be better just to use the standard int64_t and
uint64_t type names?

They don't exist in C90. They may not exist in C99.
So, I was suggesting using the standard names.

--
Ian Collins.
Jun 23 '07 #11

P: n/a
CBFalconer wrote:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
>>Charles Sullivan wrote:
... snip ...
It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.
Long long was introduced with C99. If you don't have a C99
compliant compiler (and you probably don't) they won't work.
Not true. I have a compiler that isn't C99 compliant, and it
supports "long long" just fine (if I don't invoke it in strict
C90 mode).

You have a C90 compiler with enabled extensions.
Isn't that what Keith said ("if I don't invoke it in strict C90 mode")?

--
Ian Collins.
Jun 23 '07 #12

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
>>Charles Sullivan wrote:

... snip ...

It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.

Long long was introduced with C99. If you don't have a C99
compliant compiler (and you probably don't) they won't work.

Not true. I have a compiler that isn't C99 compliant, and it
supports "long long" just fine (if I don't invoke it in strict
C90 mode).

You have a C90 compiler with enabled extensions.
Yes, of course -- which is entirely consistent with what I wrote, and
contradicts your earlier statement.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 23 '07 #13

P: n/a
Ian Collins wrote:
CBFalconer wrote:
>Ian Collins wrote:
>>Keith Thompson wrote:

You might consider defining your own types, perhaps "long_long"
and "unsigned_long_long", in an application-specific header;
these would be typedefs for long long and unsigned long long
where they're available, and for whatever other type is
appropriate where they're not. You should be able to detect
whether long long exists by checking "#ifdef LLONG_MAX" (after
#include <limits.h>).

Wouldn't it be better just to use the standard int64_t and
uint64_t type names?

They don't exist in C90. They may not exist in C99.

So, I was suggesting using the standard names.
Then you run into problems when they are defined in that system.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 23 '07 #14

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Ian Collins wrote:
>CBFalconer wrote:
>>Ian Collins wrote:
Keith Thompson wrote:
You might consider defining your own types, perhaps "long_long"
and "unsigned_long_long", in an application-specific header;
these would be typedefs for long long and unsigned long long
where they're available, and for whatever other type is
appropriate where they're not. You should be able to detect
whether long long exists by checking "#ifdef LLONG_MAX" (after
#include <limits.h>).

Wouldn't it be better just to use the standard int64_t and
uint64_t type names?

They don't exist in C90. They may not exist in C99.

So, I was suggesting using the standard names.

Then you run into problems when they are defined in that system.
So you define them yourself if and only if they're not already defined.

There's no good portable way in C to determine whether they're already
defined, but there are a number of ways to do so outside the language
(autoconf is one).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 23 '07 #15

P: n/a
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
>Ian Collins wrote:
>>CBFalconer wrote:
Ian Collins wrote:
Keith Thompson wrote:
>
>You might consider defining your own types, perhaps "long_long"
>and "unsigned_long_long", in an application-specific header;
>these would be typedefs for long long and unsigned long long
>where they're available, and for whatever other type is
>appropriate where they're not. You should be able to detect
>whether long long exists by checking "#ifdef LLONG_MAX" (after
>#include <limits.h>).
>
Wouldn't it be better just to use the standard int64_t and
uint64_t type names?

They don't exist in C90. They may not exist in C99.

So, I was suggesting using the standard names.

Then you run into problems when they are defined in that system.

So you define them yourself if and only if they're not already
defined. There's no good portable way in C to determine whether
they're already defined, but there are a number of ways to do so
outside the language (autoconf is one).
That's another matter entirely. What I suggest is trying VERY hard
to stick to the normal brew of short, int, long.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 24 '07 #16

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
>>Ian Collins wrote:
CBFalconer wrote:
Ian Collins wrote:
>Keith Thompson wrote:
>>You might consider defining your own types, perhaps "long_long"
>>and "unsigned_long_long", in an application-specific header;
>>these would be typedefs for long long and unsigned long long
>>where they're available, and for whatever other type is
>>appropriate where they're not. You should be able to detect
>>whether long long exists by checking "#ifdef LLONG_MAX" (after
>>#include <limits.h>).
>>
>Wouldn't it be better just to use the standard int64_t and
>uint64_t type names?
>
They don't exist in C90. They may not exist in C99.

So, I was suggesting using the standard names.

Then you run into problems when they are defined in that system.

So you define them yourself if and only if they're not already
defined. There's no good portable way in C to determine whether
they're already defined, but there are a number of ways to do so
outside the language (autoconf is one).

That's another matter entirely. What I suggest is trying VERY hard
to stick to the normal brew of short, int, long.
Sure, if you ignore the OP's explicit requirement it's really easy.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 24 '07 #17

P: n/a

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
CBFalconer <cb********@yahoo.comwrites:
>Ian Collins wrote:
>>CBFalconer wrote:
Ian Collins wrote:
Keith Thompson wrote:
>You might consider defining your own types, perhaps "long_long"
>and "unsigned_long_long", in an application-specific header;
>these would be typedefs for long long and unsigned long long
>where they're available, and for whatever other type is
>appropriate where they're not. You should be able to detect
>whether long long exists by checking "#ifdef LLONG_MAX" (after
>#include <limits.h>).
>
Wouldn't it be better just to use the standard int64_t and
uint64_t type names?

They don't exist in C90. They may not exist in C99.

So, I was suggesting using the standard names.

Then you run into problems when they are defined in that system.

So you define them yourself if and only if they're not already defined.

There's no good portable way in C to determine whether they're already
defined, but there are a number of ways to do so outside the language
(autoconf is one).
<OT>
Autoconf is also not portable. Nor reliable.
</OT>
Jun 24 '07 #18

P: n/a
"Barry" <ba****@nullhighstream.netwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
[...]
>So you define them yourself if and only if they're not already defined.

There's no good portable way in C to determine whether they're already
defined, but there are a number of ways to do so outside the language
(autoconf is one).

<OT>
Autoconf is also not portable. Nor reliable.
</OT>
I didn't mean to imply otherwise.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 24 '07 #19

P: n/a
On Fri, 22 Jun 2007 14:55:14 -0400, Charles Sullivan wrote:
I maintain/enhance some inherited FOSS software in C which has
compiler options for quite a few different Unix-like operating
systems, many of which I've never even heard of.

It would be convenient (and for some things possibly necessary)
to use long long integer and/or unsigned long long integer
variables.

How widely supported are these variable types? How long ago were
they introduced? I notice they are not mentioned in K&R #2.

Thanks for your help.

Regards,
Charles Sullivan
Many thanks to all who responded. Your comments have been
very useful.

For those who wondered why I needed long longs:
My app makes extensive use of unsigned long bitmaps and bitwise
logic. Enhancements to the app occasionally require defining new
bit positions and in some cases I'm getting close to running out.
It would be far simpler to switch to unsigned long long than to
reprogram to use multiple unsigned longs.

Thanks again.

Regards,
Charles Sullivan
Jun 24 '07 #20

P: n/a
On Sun, 24 Jun 2007 10:22:43 -0400, Charles Sullivan
<cw******@triad.rr.comwrote:

snip
>
Many thanks to all who responded. Your comments have been
very useful.

For those who wondered why I needed long longs:
My app makes extensive use of unsigned long bitmaps and bitwise
logic. Enhancements to the app occasionally require defining new
bit positions and in some cases I'm getting close to running out.
It would be far simpler to switch to unsigned long long than to
reprogram to use multiple unsigned longs.
It might be even simpler to switch once to an array of unsigned char
and never have to worry about type sizes again.
Remove del for email
Jun 25 '07 #21

P: n/a
On Sun, 24 Jun 2007 17:17:56 -0700, Barry Schwarz wrote:
On Sun, 24 Jun 2007 10:22:43 -0400, Charles Sullivan
<cw******@triad.rr.comwrote:

snip
>>
Many thanks to all who responded. Your comments have been
very useful.

For those who wondered why I needed long longs:
My app makes extensive use of unsigned long bitmaps and bitwise
logic. Enhancements to the app occasionally require defining new
bit positions and in some cases I'm getting close to running out.
It would be far simpler to switch to unsigned long long than to
reprogram to use multiple unsigned longs.

It might be even simpler to switch once to an array of unsigned char
and never have to worry about type sizes again.
Thanks for the suggestion. However just the thought of all the
recoding that would require makes my brain hurt :-)

Regards,
Charles Sullivan
Jun 25 '07 #22

This discussion thread is closed

Replies have been disabled for this discussion.