473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

sizeof(type) in various systems

1)As i was going through the previous threads of clc I come accross that
sizeof(type) could varies according to the system.
limit.h macro constant(CHAR_xxx,INT_xxx,etc) will do the job of allocatating
the number of bits according to the system. I am wrong in understanding?

2)can any body post the details of sizeof(type) in different systems
NOTE:If this is a OT then direct me or if this Question asked in previous
thread can any body give the link.

Thanks

----------------
DON'T MAIL ME
----------------
Nov 14 '05 #1
5 1544
In 'comp.lang.c', da***********@yahoo.com wrote:
1)As i was going through the previous threads of clc I come accross that
sizeof(type) could varies according to the system.
If you meant "the value returned by the expression 'sizeof (type)'", you are
correct. To be more generic, say that it can vary according to the
implementation. (such compiler running on such system running on such
machine)

For example, on my PC, I have Windows 98 SE. If I use Borland C 3.1 sizeof
(int) is 2. If I use VC++6 or Dev-C++, it's 4.
limit.h macro constant(CHAR_xxx,INT_xxx,etc) will do the job of
allocatating the number of bits according to the system. I am wrong in
understanding?
Actually, the values on limits.h are informative. They inform the programmer
about the limits supported by the types on this peculiar implementation of
the C-language. If I follow my previous examples, here are the values I have
in the <limits.h> headers of Borland C++ 3.1 :

#define INT_MAX 0x7FFF
#define INT_MIN ((int)0x8000)
#define UINT_MAX 0xFFFFU

and of Dev-C++ :

#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX-1)

#define UINT_MAX 0xffffffff

*These values must not be changed by the user*. They belong to the
implementation, like all what is in the <> headers.
2)can anybody post the details of sizeof(type) in different systems


Why do you want that exactly ? How such an information could be
exhaustive or useful ?

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #2
da***********@yahoo.com wrote:
1)As i was going through the previous threads of clc I come accross that
sizeof(type) could varies according to the system.
limit.h macro constant(CHAR_xxx,INT_xxx,etc) will do the job of allocatating
the number of bits according to the system. I am wrong in understanding?
You are wrong. First of all, it's called <limits.h>, note spelling.
Then, the macros in <limits.h> do not allocate anything whatsoever; they
are, as you say, simple constants. They evaluate to numbers, not to
function calls. Finally, the numbers they evaluate to are, surprise,
usually _limits_, not bit counts; that is, if you have an unsigned int
with 16 value bits, then UINT_MAX will be 2**16 == 65536, _not_ 16.

The one exception to this is CHAR_BIT, which gives you the number of
bits in a char. Together with sizeof, this one macro can be used to
figure out the bit count used by a type or an object - but note, this
bit count includes not just value and sign bits, but also padding bits.
Thus, it may (usually isn't for integers, but _is_ allowed to) be larger
than seems consistent with the values in <limits.h>.
2)can any body post the details of sizeof(type) in different systems


Not me, but why do you need to know how large a short int is under
Zibble C on an Arawak machine?

Richard
Nov 14 '05 #3
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]
Finally, the numbers they evaluate to are, surprise, usually
_limits_, not bit counts; that is, if you have an unsigned int with
16 value bits, then UINT_MAX will be 2**16 == 65536, _not_ 16.


<QUIBBLE>2**16-1 == 65535</QUIBBLE>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #4
Keith Thompson <ks***@mib.org> wrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]
Finally, the numbers they evaluate to are, surprise, usually
_limits_, not bit counts; that is, if you have an unsigned int with
16 value bits, then UINT_MAX will be 2**16 == 65536, _not_ 16.


<QUIBBLE>2**16-1 == 65535</QUIBBLE>


Bloody 'ell. I even had n869 in front of me when I typed that. Either I
can't read, I can't write, or I can't do math, you choose.

Richard
Nov 14 '05 #5
In <a3*************************@posting.google.com> da***********@yahoo.com writes:
2)can any body post the details of sizeof(type) in different systems


Yup. All you want to know is that sizeof(char) is 1 on different systems,
so you never need to write sizeof(char) in your portable C code. For
anything else, use sizeof, because this is why it exists in the language.

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

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

Similar topics

7
by: dam_fool_2003 | last post by:
#include<stdio.h> int main(void) { unsigned int a=20,b=50, c = sizeof b+a; printf("%d\n",c); return 0; } out put: 24
42
by: Christopher C. Stacy | last post by:
Some people say sizeof(type) and other say sizeof(variable). Why?
18
by: sabarish | last post by:
Hi to one and all one of the developer asked me "Can u implement one user defined funtion similar to the sizeof operaor in C Programming Language". is it possible in C ?
29
by: lnitsu | last post by:
Hello I've got a simple question regarding sizeof operator. why sizeof 'a' return 4? (Note the argument is without parenthesis) If anybody is so kind to answer ... TIA
90
by: pnreddy1976 | last post by:
Hi, How can we write a function, which functionality is similar to sizeof function any one send me source code Reddy
28
by: Howard Bryce | last post by:
I have come across code containing things like sizeof int How come that one can invoke sizeof without any parentheses surrounding its argument? Is this admissible within the standard? Can it...
4
by: Ole | last post by:
Hi, Doing this will work: double *dPointer; result = sizeof(*dPointer); if I want the size (in this case 8) of the type that the pointer is pointing at, but is there a more correct way to...
10
by: Yevgen Muntyan | last post by:
Consider the following macro: #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type))) The intent is to wrap raw memory allocation of N bytes into a macro which returns allocated chunk of memory...
28
by: Trups | last post by:
HI, I want to dynamically allocate array variable of type LPWSTR. Code looks like this... main() { LPWSTR *wstr; int count = Foo (wstr); for (int i = 0; i < count; i++)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.