473,671 Members | 2,403 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 1320
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********@yah oo.co.in> wrote in message
news:a2******** *************** ***@posting.goo gle.com...
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********@yah oo.com) (cb********@wor ldnet.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********@yaho o.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********@yah oo.co.in> wrote in message news:a2******** *************** ***@posting.goo gle.com...
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
2241
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 have a couple problems that include the magical 4mb number. 1. My problem is that when my file is over the 4 mb limit. If the 4 MB limit is met then the code on the button I use doesn't even fire (as I have code to check the file length before...
11
4274
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 *fp; fp=fopen(name,"rb"); /*Here's where fread should go but k&r p 248 didn't help much */ fclose(fp);}
11
11921
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 are wasted, or my assumption is wrong? If my assumption is right, what are the performance issues in retrieving value of a character variable over other data types like integer, double or float.
15
1920
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? (if it's relevent, use standard size of datatypes) a) Code: struct
53
4285
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 sizeof(char) == sizeof(int). TMS320C5402 DSP (with 16-bit word size). both returns one. So, it holds true.
35
5445
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 : %d\n",sizeof(unsigned char)); printf("short : %d\n",sizeof(short)); printf("unsigned short : %d\n",sizeof(unsigned short)); printf("int : %d\n",sizeof(int));
4
7211
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 executionTimeout="1800" maxRequestLength="5000" /> When the file size exceed 5000 (kb) I receive the right exception (System.Web.Services.Protocols.SoapException) that tell me that the dimension
5
2577
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 = fsInput.Length
5
39231
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 have a 32-bit machine, then what will be the size of int? Thanks.
26
1987
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 in deciding the size of such data types?
0
8478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8397
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8919
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8599
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7439
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.