PDA

View Full Version : differnet sizeof int on same processor architecture



anon10020
06-04-2012, 07:04 AM
Hello Sir,

When we use datatype int in turbo C/C++ compiler, its size is 2 bytes, but when we use int in gcc its size is 4bytes,
even after the processor architecture is x86 for both. So how is it possible as per reference to C Data Types slide in Data Types Section?

Thank You
Anon10020

anup
06-04-2012, 07:59 AM
Anon10020,

TurboC++ is running the processor in 16 bit mode and not 32bits and hence that is the size of int on it.

Thanks,

Anup

anon10128
20-08-2013, 06:38 PM
Hi sir,
I have a laptop with 64 bit processor and ubuntu 12 installed on it. But still I get size of int as 4 bytes. Does it mean the ubuntu which I have installed is 32 bit or size of int on 64 bit processor is 4 bytes only?

Thank you.

anup
20-08-2013, 06:47 PM
Anon10128,

uname -a on Ubuntu will tell you the architecture on which it is installed. Typically on a 64bit machine the size of 'int' will still be 4 bytes, but, long will be 8 bytes.

You can use gcc options -m32 and -m64 to force compilation for a particular machine type i.e. 32bit r 64bit respectively.

Thanks,
Anup

anon10128
21-08-2013, 10:15 AM
Hi sir,

uname -a gives

Linux ubuntu 3.2.0-51-generic #77-Ubuntu SMP Wed Jul 24 20:18:19 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

but when i compiled program with gcc -m32 option it gives error as--

In file included from /usr/include/stdio.h:28:0, from sizeof_struct.c:1:
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
compilation terminated.

Please help me. I wanted to check whether structure is word aligned in 32 bit or not?

thank you.

anon10128
21-08-2013, 10:18 AM
Can I give gcc -m16 for forcing it for 16 bit architecture? Or is there any other option?

Thank you.

anup
21-08-2013, 10:20 AM
Anon10128,

Since it ways x86_64 it is a 64 bit architecture. The compilation is failing because you may be missing packages, please Google around for compatibility libs on Ubuntu.

Check the man page of gcc to see if it supports 16 bit architectures. I don't think a generic Ubuntu installation will.

Thanks,
Anup

anon10128
21-08-2013, 11:03 AM
Hi sir,

x86_64 does not mean 64 bit processor?

thank you.

anup
21-08-2013, 11:05 AM
Sorry, that was a typo it means a 64-bit architecture. I have fixed the post. If it says i686, then it is a 32-bit architecture.

Thanks,
Anup

anon10128
21-08-2013, 11:12 AM
Thank you sir.

anon10128
23-10-2013, 03:11 PM
Hi sir,

uname -a gives

Linux ubuntu 3.2.0-51-generic #77-Ubuntu SMP Wed Jul 24 20:18:19 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

In this which is kernel version and which is ubuntu version? And what is that #77?

Thank you.

anup
23-10-2013, 06:35 PM
Hi,

You can obtain the Linux kernel version from cat /proc/version. The version printed here is the Ubuntu version. Unfortunately, I do not know what #77 stands for.

Thanks,
Anup