LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-18-2006, 05:44 AM   #1
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
64 bit integer


hi,
In one of my structure one field is of 64 bit width. I know that i can use "long long" data type of linux, but it is linux extension. And i want my program to be portable. Can any body suggest me how can i declare and manipulate that field. Thanks in advance.

regards
Rajesh
 
Old 07-18-2006, 05:53 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
"long long" does not guarantee a 64bit int.

you should be able to include stdint.h on linux and mac
which has datatypes.
I havn't come across too many windows boxs which have this file so I do the following, which may help you.
This is assuming that it is a 64 bit machine and that I have already determinded the box on which it is running.
Code:
#	if ( defined (DE_WINDOWS_BUILD) )
		typedef signed	__int8		int8;
		typedef unsigned __int8		uint8;
		typedef signed	__int16		int16;
		typedef unsigned __int16	uint16;
		typedef signed	__int32		int32;
		typedef unsigned __int32	uint32;
		typedef signed __int64          int64;
		typedef unsigned __int64        uint64;
#	elif (defined(DE_UNIX_BUILD) || defined(DE_MAC_BUILD))
#		include <stdint.h>
		typedef int8_t				int8;
		typedef uint8_t				uint8;
		typedef int16_t				int16;
		typedef uint16_t			uint16;
		typedef int32_t				int32;
		typedef uint32_t			uint32;
		typedef int64_t                         int64;
		typedef uint64_t                        uint64;
#	endif

Last edited by dmail; 07-18-2006 at 05:55 AM.
 
Old 07-18-2006, 06:58 AM   #3
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Original Poster
Rep: Reputation: 15
If the machine is 32-bit

hi dmail,
Thanks for u r reply.
If the processor is of 32-bit type then i think we dont have datatype
uint64.
So what will be the scenario in that case. I hope it is clear.


Regards,
Rajesh.
 
Old 07-18-2006, 07:20 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
If the processor is of 32-bit type then i think we dont have datatype
uint64.
I don't have 64bit machine, but a 32bit gives the output below. I will have you check within windows but I would assume it also defines a 64bit int which is probably a struct with high and low bits.

Code:
#include <iostream>
#include <stdint.h>

int main(int argc, char *argv[])
{
	std::cout <<"int32 :" <<sizeof(int32_t) <<std::endl
	<< "int64 :" <<sizeof(int64_t) <<std::endl;

	return 1;
}
output:
int32 :4
int64 :8
 
Old 07-18-2006, 07:43 AM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Running this on widows (32bit) gives the same results so I can't see there being a problem

Code:
#include <iostream>

int main(int argc, char *argv[])
{
	std::cout <<"int32 :" <<sizeof(__int32) <<std::endl
	<< "int64 :" <<sizeof(__int64) <<std::endl;
	return 1;
}
output:
int32 :4
int64 :8
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert 64 bit integer to char array in C++ syseeker Programming 2 06-27-2006 04:33 AM
32 bit or 64 bit install - is 32 bit easier for a newbie? dms05 Linux - Newbie 3 05-19-2006 04:05 PM
Which version of 32 bit redhat will install on IBM xSeries 366 (64 bit)? Hello123 Linux - Hardware 2 09-14-2005 06:50 AM
64 bit integer fahad153 Programming 9 08-26-2003 03:03 AM
Graphic Card that Supports displaying 8-bit and 24-bit images simultaneously yrraja Linux - Hardware 2 04-30-2003 07:41 AM


All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration