LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-28-2011, 01:08 AM   #1
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 115

Rep: Reputation: 3
int size is compiler dependent or OS dependent


int size is compiler dependent or OS dependent please do not answer in yes or no,some additional details regarding this will be helpful to me.
 
Old 11-28-2011, 03:15 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,934

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
It depends on the platform (which includes processor, OS, compiler, compiler-options, etc). Ask more specific questions, you will get more specific answers.

Last edited by NevemTeve; 11-28-2011 at 03:29 AM.
 
Old 11-28-2011, 04:10 AM   #3
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by tarunchawla View Post
int size is compiler dependent or OS dependent please do not answer in yes or no,some additional details regarding this will be helpful to me.
I assume that you're talking about C or C++.
size of int depends on the compiler, but compiler may theoretically change it based on target platform, CPU or compiler switches.
 
1 members found this post helpful.
Old 11-28-2011, 05:33 AM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
Yeah, it's a bit of both - on the one hand, the compiler mandates it because it affects the instructions it generates, but on the other hand a standards-compliant compiler is supposed to choose the "most natural" size for the architecture. In practice, it doesn't matter so long as you don't make any assumptions about its size (i.e. use sizeof(int) for moving/storing int values and the intX_t/uintX_t typedefs in stdint.h when you need fixed-size integral values).

Last edited by JohnGraham; 11-28-2011 at 05:42 AM.
 
Old 11-30-2011, 04:46 AM   #5
King_DuckZ
Member
 
Registered: Nov 2009
Location: Rome, IT
Distribution: Sabayon
Posts: 61

Rep: Reputation: 2
The real problem imo is why this is an issue to you. You should have typedefs for u16, u32, i32 and so on and you should (almost) never see an int in your code, even less monsters like DWORD, QWORD and the likes o.O
If your language is c++ I can give you a solution for that problem that doesn't even use #ifdefs.
 
  


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
Regarding dependent kernel modules dinkyverma279 Linux - Kernel 2 06-10-2009 04:59 PM
Gnome has become dependent upon Compiz DJOtaku Linux - Desktop 5 04-10-2008 06:26 PM
gcc dependent packages? trumpetdork Linux - Software 1 04-08-2005 06:21 PM
autoloading dependent modules saajii Programming 1 09-15-2004 01:04 AM
two dependent rpms pasalacqua128 Linux - Software 1 06-14-2004 03:54 PM


All times are GMT -5. The time now is 03:17 AM.

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