LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   int size is compiler dependent or OS dependent (http://www.linuxquestions.org/questions/programming-9/int-size-is-compiler-dependent-or-os-dependent-915923/)

tarunchawla 11-28-2011 01:08 AM

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.

NevemTeve 11-28-2011 03:15 AM

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

SigTerm 11-28-2011 04:10 AM

Quote:

Originally Posted by tarunchawla (Post 4535916)
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.

JohnGraham 11-28-2011 05:33 AM

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).

King_DuckZ 11-30-2011 04:46 AM

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.


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