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

C

Charles Sullivan

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
 
R

Robert Gamble

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
 
K

Keith Thompson

Charles Sullivan said:
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>).
 
C

CBFalconer

Charles said:
.... 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.
 
K

Keith Thompson

CBFalconer said:
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*.
 
I

Ian Collins

Keith said:
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?
 
U

user923005

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).
 
K

Keith Thompson

Ian Collins said:
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.h> if 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.
 
C

CBFalconer

Keith said:
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.
 
K

Keith Thompson

CBFalconer said:
You have a C90 compiler with enabled extensions.

Yes, of course -- which is entirely consistent with what I wrote, and
contradicts your earlier statement.
 
K

Keith Thompson

CBFalconer said:
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).
 
C

CBFalconer

Keith said:
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.
 
K

Keith Thompson

CBFalconer said:
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.
 
B

Barry

Keith Thompson said:
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>
 
C

Charles Sullivan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top