473,513 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Size of Int on a machine

How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?
Nov 14 '05 #1
5 1306
aruna wrote:

How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?


Not in Standard C, although some implementations allow
it as a non-conforming extension. What you *can* do, though,
is check the range of an int, using the INT_MAX and INT_MIN
macros defined in <limits.h>. For example,

#include <limits.h>
#if INT_MAX >= 1000000
typedef int Million;
#else
typedef long Million;
#endif

--
Er*********@sun.com
Nov 14 '05 #2
"aruna" <ar********@yahoo.co.in> wrote in message
news:a2**************************@posting.google.c om...
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?


You can't do it directly in standard C. Perhaps this is a sign that your
code relies on machine specifics too much?
Nov 14 '05 #3
aruna wrote:

How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?


#include <limits.h>

#if (INT_MAX < nnnL)
# error "int too small"
#endif

It might be simpler to use longs for the appropriate variables.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #4
In <a2**************************@posting.google.com > ar********@yahoo.co.in (aruna) writes:
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?


Yup. Include <limits.h> and examine INT_MAX.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5

"aruna" <ar********@yahoo.co.in> wrote in message news:a2**************************@posting.google.c om...
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?


A simple method would to consult the documentation,
if any, that came with the compiler.

--
Vijay Kumar R Zanvar
Movies - http://www.geocities.com/vijoeyz/misc/movies.html
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2227
by: BTHOMASinOHIO | last post by:
I am confussed on what the heck is going on ?! I have an HTML INPUT File Box on an Email Piece of an application. I know that File Size is set to 4MB in the WebConfig File and that is fine, but I...
11
4262
by: Bill Cunningham | last post by:
In fread, the type of the function is the typedef size_t. I want to rewrite a program that read binary data of mp3s. int main(){ printf("Enter name of file-> "); char name; fflush(stdout); FILE...
11
11845
by: aruna | last post by:
How is a character stored in a word aligned machine? Assuming on 64bit machine, 1 byte is reserved for a char, is it the case that only 1 byte is used to store the character and the rest 7 bytes...
15
1901
by: puzzlecracker | last post by:
Got Confused on the interview with memory alligment questions... PLEASE HELP -- How much bytes of memory will structs below take on 32 bit machine? What about 64 bit machine? Why is it different?...
53
4246
by: Neo | last post by:
Hi All, Is that true that size of a byte not necessarily 8-bit? What the std. says? If that true, then what will the size of an int, i mean what sizeof(int) should return? On my machine...
35
5412
by: Sunil | last post by:
Hi all, I am using gcc compiler in linux.I compiled a small program int main() { printf("char : %d\n",sizeof(char)); printf("unsigned char : ...
4
7206
by: vigori | last post by:
I have an application that send a file to a web service (I built both the application and the web service) I set the max file size via web.config of the web service: <httpRuntime...
5
2571
by: news.microsoft.com | last post by:
Hello, what is the most performant size for the byte array for reading/writing using 2 filestreams? example code: Dim bytearrayinput(4095) As Byte Dim rdlen As Long = 0 Dim totlen As Long...
5
39223
by: Nikhil Bokare | last post by:
Hi, It is said that the size of short,int,long,float and double depends on the machine whereas the size of char is 1-byte. Now, what do they mean by the size depends on the machine? I mean if i...
26
1954
by: rao | last post by:
On some of the compilers integer size is 2 and on some other it is 4 bytes. My doubt is who decides the size of the integer? is it plainly the compiler? Does OS or Processor also has any control...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.