473,804 Members | 4,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 41197

"ESOJAY" <es******@hotma il.com> wrote in message
news:bp******** **@news.ox.ac.u k...
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_VE R) || defined(__BORLA NDC__)
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********@iah u.ca> wrote in message
news:9T******** ****@news04.blo or.is.net.cable .rogers.com...

"ESOJAY" <es******@hotma il.com> wrote in message
news:bp******** **@news.ox.ac.u k...
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_VE R) || defined(__BORLA NDC__)
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******@hotma il.com> wrote in message
news:bp******** **@news.ox.ac.u k...
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********@iah u.ca> wrote in message
news:Eo******** *****@news04.bl oor.is.net.cabl e.rogers.com...

"ESOJAY" <es******@hotma il.com> wrote in message
news:bp******** **@news.ox.ac.u k...
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**********@n ews.ox.ac.uk> "ESOJAY" <es******@hotma il.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
12655
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 no Win32 specials allowed....
4
2167
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 string ' --> each element is an integer in the range 0-255 Dim Big as int64 = 0
5
5330
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 parameter. VB6 give the following error Compile Error: Function or interface marked as restricted, or the function use an automation type not supported in Visual Basic.
10
2900
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 other way to get similar effect for Int64 type? Another question less urging question is, why long variables can't be used as volatile? I understand that in 32-bit arch. 64-bit operations are not atomic, but seems that there could be locks or so...
14
9649
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 9,223,372,036,854,775,807. But I'm not good with the E+??? notation so when I'm told double holds -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values; 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values.
12
3041
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
10764
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 Int64 to hex? Thanks,
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.