Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-28-2011, 12:08 AM   #1
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

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, 02:15 AM   #2
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,503

Rep: Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080
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 02:29 AM.
Old 11-28-2011, 03:10 AM   #3
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
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, 04:33 AM   #4
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
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 04:42 AM.
1 members found this post helpful.
Old 11-30-2011, 03:46 AM   #5
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.


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 03:59 PM
Gnome has become dependent upon Compiz DJOtaku Linux - Desktop 5 04-10-2008 05:26 PM
gcc dependent packages? trumpetdork Linux - Software 1 04-08-2005 05:21 PM
autoloading dependent modules saajii Programming 1 09-15-2004 12:04 AM
two dependent rpms pasalacqua128 Linux - Software 1 06-14-2004 02:54 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:00 AM.

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