473,390 Members | 1,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Defining int64

Is "typedef long long int64" the best way to define an int64 type in c? Are
there better alternatives?

Thanks,
ESOJAY

--
ESOJAY
Nov 13 '05 #1
6 41132

"ESOJAY" <es******@hotmail.com> wrote in message
news:bp**********@news.ox.ac.uk...
Is "typedef long long int64" the best way to define an int64 type in c? Are there better alternatives?


I use this in my code

#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 ulong64;
typedef signed __int64 long64;
#else
typedef unsigned long long ulong64;
typedef signed long long long64;
#endif

It works for GCC, MSVC and BorlandC which will cover the vast majority of
platforms.

Tom
Nov 13 '05 #2
Thanks.
Unfortunately, I am constrained to use MIPSpro C compiler, which dosen't
seem to understand _int64 or __int64.

ESOJAY
"Tom St Denis" <to********@iahu.ca> wrote in message
news:9T************@news04.bloor.is.net.cable.roge rs.com...

"ESOJAY" <es******@hotmail.com> wrote in message
news:bp**********@news.ox.ac.uk...
Is "typedef long long int64" the best way to define an int64 type in c?

Are
there better alternatives?


I use this in my code

#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 ulong64;
typedef signed __int64 long64;
#else
typedef unsigned long long ulong64;
typedef signed long long long64;
#endif

It works for GCC, MSVC and BorlandC which will cover the vast majority of
platforms.

Tom

Nov 13 '05 #3

"ESOJAY" <es******@hotmail.com> wrote in message
news:bp**********@news.ox.ac.uk...
Thanks.
Unfortunately, I am constrained to use MIPSpro C compiler, which dosen't
seem to understand _int64 or __int64.


It doesn't allow "long long"? Then tell the MIPSpro C compiler guys to
update their compiler :-)

Or use GCC...

Tom
Nov 13 '05 #4

"Tom St Denis" <to********@iahu.ca> wrote in message
news:Eo*************@news04.bloor.is.net.cable.rog ers.com...

"ESOJAY" <es******@hotmail.com> wrote in message
news:bp**********@news.ox.ac.uk...
Thanks.
Unfortunately, I am constrained to use MIPSpro C compiler, which dosen't
seem to understand _int64 or __int64.


It doesn't allow "long long"? Then tell the MIPSpro C compiler guys to
update their compiler :-)

Or use GCC...

Tom


It allows long long. I'm just not sure if long long is always going to be 64
bits on any machine I port the code to.

ESOJAY
Nov 13 '05 #5
ESOJAY wrote:

It allows long long. I'm just not sure if long long is always going to be 64
bits on any machine I port the code to.


The situation is a little bit screwy ...

The C99 Standard requires `long long' to be at least 64
bits wide, but permits it to be wider. If you need 64 bits
or more but don't want to waste space if `long long' turns
out to be 128 bits, say, use `int_least64_t' from <stdint.h>.

Still in C99, if you need *exactly* 64 bits you can use
`int64_t', also from <stdint.h>. However, C99 does not require
that this type be supported by all implementations, so you can't
count on it being available. It may be enough that your code
will fail to compile on such an implementation; the person
attempting to port it will at least be ade aware of the trouble.

The earlier C90 Standard did not define `long long' --
in fact, using `long long' in a program was a syntax error.
Still, many compilers provided it as an extension when
invoked in a non-strict mode. About the best you can do
is to hope that such compilers also "advertise" the fact
through the <limits.h> macros, so you can test at compile
time whether a suitable `long long' exists. Making the
test is just a bit tricky because the preprocessor may
not be able to handle such large values; here's one way:

#include <limits.h>
#if (LLONG_MAX >> 31) >> 31 == 1
typedef long long int64;
#else
#error "No 64-bit integer type!"
#endif

(Obviously, you could change `==' to `>=' if you need an
"at least" rather than an "exactly" 64-bit type.)

This isn't 100% certain to work, though. `LLONG_MAX'
is mandated by C99 but was (obviously) absent from C90,
and a compiler that decided to provide `long long' before
C99 appeared might not have described the type in exactly
the same way C99 would eventually require. Also, the
support for `long long' in things like printf() may not
be exactly what C99 eventually specified. Still, a test
like this is probably the best you can do for a pre-C99
implementation.

--
Er*********@sun.com
Nov 13 '05 #6
In <bp**********@news.ox.ac.uk> "ESOJAY" <es******@hotmail.com> writes:
Is "typedef long long int64" the best way to define an int64 type in c? Are
there better alternatives?


long long is an adequate definition for a 64-bit integer on all the
compilers supporting this type that I'm aware of. However, compilers
that do not originate under Unix have a tendency to use a different name
for their 64-bit integer types (if they support them at all). And, of
course, I/O on such types is performed in a platform specific way.

If your C89 compiler supports long long as an extension, you can no longer
invoke the compiler in conforming mode if you use it. Depending on your
purposes, this may or may not be an issue.

The advantage of names like __int64 is that you can use them even when
invoking the compiler in conforming mode, without requiring a diagnostic.

No such problems for C99 compilers (long long is a standard C99 type),
but they are few and far between.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

82
by: zardoz | last post by:
I've got this problem: unsigned long long lTemp; char cLargeNum="1324567890"; sscanf(clargeNum,"%llu",&lTemp); which under Win32 isn't working*. My program needs to compile under posix so...
4
by: Simon Devlin | last post by:
Hi folks, I've been bashing my head against this all afternoon and am now totally baffled. Given this (a simple routine to turn a ip address string into an decimal) <snip> Dim Parts(3) as...
5
by: harishashim | last post by:
I have gone through necessary step and have been able to use a .Net libraries (created using C#) in VB6. It run good untill I try to use certain function in the library that is using Int64 type as...
10
by: Lau Lei Cheong | last post by:
Hello, I really need to use volatile System.Int64 for a .NET v1.1 program in C#. But the compiler complains "a volatile field can not be of type long". How to work around it? Or is there any...
14
by: cj | last post by:
VB2003. I need a large positive integer. Which is larger int64 or double? I see int64 also apparently is known as long and will hold -9,223,372,036,854,775,808 through...
12
by: Allen | last post by:
My C extension works wrong, and debug it, found that sizeof (INT64) = 4, not 8. I compile on Windows XP platform. Please tell me how to fix it to support INT64? Thanks.
3
by: Tim Sprout | last post by:
To convert hex to Int64 I can use: string hex = "413208A97245F5AE"; Int64 intFromHex = System.Convert.ToInt64(hex, 16); //intFromHex = 4697826885160531374 How do I reverse this, and convert...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.