473,902 Members | 3,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Natural size: int


On modern 32-Bit PC's, the following setup is common:

char: 8-Bit
short: 16-Bit
int: 32-Bit
long: 32-Bit

"char" is commonly used to store text characters.
"short" is commonly used to store large arrays of numbers, or perhaps wide
text characters (via wchar_t).
"int" is commonly used to store an integer.
"long" is commonly used to store an integer greater than 65535.

Now that 64-Bit machines are coming in, how should the integer types be
distributed? It makes sense that "int" should be 64-Bit... but what should
be done with "char" and "short"? Would the following be a plausible setup?

char: 8-Bit
short: 16-Bit
int: 64-Bit
long: 64-Bit

Or perhaps should "short" be 32-Bit? Or should "char" become 16-Bit (i.e.
16 == CHAR_BIT).

Another semi-related question:

If we have a variable which shall store the quantity of elements in an
array, then should we use "size_t"? On a system where "size_t" maps to
"long unsigned" rather than "int unsigned", it would seem to be inefficient
most of the time. "int unsigned" guarantees us at least 65535 array
elements -- what percentage of the time do we have an array any bigger than
that? 2% maybe? Therefore would it not make sense to use unsigned rather
than size_t to store array lengths (or the positive result of subtracting
pointers)?

--

Frederick Gotham
Aug 8 '06
78 3922
In article <zj************ *******@news.in digo.ieFrederic k Gotham <fg*******@SPAM .comwrites:
....
Are you familiar with C++ at all? If so, you'd know that classes and
templates are far more than simple macro and typedef substitution.
I do not know much about C++, but have used other languages that extensively
use overloading of operators (Algol 68 and Ada) and functions (Ada and
Fortran for standard functions). Hence my question:
Put them together and you've got a very powerful tool. A sample usage might
be to write a class called "Int1024" which is a 1024-Bit integer, and to
use operator overloading to make it behave like a built-in integer, so that
we can simply do:
Int1024 i = 56;
i *= 3;
and i * 3 and 3 * i and i * i, I suppose. But doesn't that require the
definition of three multiplication operators?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 10 '06 #71
Dik T. Winter posted:
and i * 3 and 3 * i and i * i, I suppose. But doesn't that require the
definition of three multiplication operators?
<OFF TOPIC>

Not really. Firstly you define the *= operator:

class MyInt {
private:

int val[6];

public:

MyInt &operator*=(MyI nt const &rhs)
{
int *p = val;
int const *prhs = rhs.val;

*p++ *= *prhs++;
*p++ *= *prhs++;
*p++ *= *prhs++;
*p++ *= *prhs++;
*p++ *= *prhs++;
*p++ *= *prhs++;

return *this;
}
};

Then you simply pigg-back off it:

MyInt operator*(MyInt lhs, MyInt const &rhs)
{
return lhs *= rhs;
}

You can make an "int" convert implicitly to a "MyInt" by supplying a
constructor which takes a sole "int" parameter.

--

Frederick Gotham
Aug 10 '06 #72

jacob navia wrote:
ro***********@y ahoo.com wrote:
The lcc-win32 C compiler provides a 128 bit integer, and it
will be more and more common in the near future as 64 bit
machines become common. A 64 bit machine can do 128 bit
arithmetic quite fast. And that will really finish it since

pow(2,128) = 3.4028236692093 846346337460743 1768211456E38 exactly

If you imagine that the smallest bill of currency X is a 10 million
bill, and its thickness is 0.1mm, to a pile worth 3.4e38 of
that currency would measure around 3.59E11 Light years.

The radius of the known universe is only around 1.3E9 light years.

So, we are protected against inflation with 128 bits. :-)

As I mentioned, the problem happens first with intermediate results, so
this is the wrong comparison. OTOH, 128 bit intermediate results ought
to be sufficient for most cases, although will require some care at
times.

Aug 11 '06 #73
Frederick Gotham said:

<snip>
Are you familiar with C++ at all?
If I want C++, I know where to find it. Please confine C++ discussions to
newsgroups where they are topical. Thank you.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 11 '06 #74
jacob navia <ja***@jacob.re mcomp.frwrote:
Ian Collins wrote:
Isn't this a case of if the cap doesn't fit, use another one?

You could achieve what you describe in a language that supports operator
overloading on user defined types.

Yes. That is why [spam - ed.] proposes to enhance the language with that
feature. It is needed in MANY situations
No, it isn't.
and it doesn't complexify the language at all.
^^^^^^^^^^
*THWAP* You're not George Pedestrian Bush, so don't imitate him

And yes, it does. Considerably. Most importantly, it makes any code I
read in C-plus-overloading less reliable than code in C.
operator overloading is a MUST for C.
On the contrary, it is greatly to be eschewed.
P.S. flames >/dev/null
P.S. Any future spam >your own toy newsgroup, please.

Richard
Aug 11 '06 #75
Richard Heathfield <in*****@invali d.invalidwrites :
Frederick Gotham said:

<snip>
>Are you familiar with C++ at all?

If I want C++, I know where to find it. Please confine C++ discussions to
newsgroups where they are topical. Thank you.
Yawn. It was in the context of a C discussion.
Aug 11 '06 #76
jacob navia wrote:
The lcc-win32 C compiler provides a 128 bit integer, and it
will be more and more common in the near future as 64 bit
machines become common. A 64 bit machine can do 128 bit
arithmetic quite fast. And that will really finish it since
Because I hate you so very much I wrote

http://math.libtomcrypt.com/ltmpp.zip

Which is a C++ wrapper around my LTM library. It's no more valid C
than your extensions. However, it's also portable C++ and is the
"smart" way to deal with this.

If people really wanted something like

bignum a;
a = 2; a <<= 128;

Then C++ is the way to achieve it. Which is what my C++ code does.
But instead of being tied to some crappy halfbreed compiler like yours,
any conforming C++ compiler will handle my code. It will work in Linux
and BSD just as happily as in Windows, etc. Oh and my C++ class will
support ANY size integer (within reasonable limits) not just compile
time fixed size integers.

This is what separates us real software developers from the script
kiddie hackers like you who just don't get how to work in a team.

Sorry for posting about C++ on clc but Navia really needs to get beaten
back into reality.

Tom

Aug 11 '06 #77


Keith Thompson wrote On 08/10/06 18:54,:
Eric Sosman <Er*********@su n.comwrites:
>>
Off-hand, I cannot think of any C operator that is *not*
overloaded. No, not even the comma operator.


I was insufficiently precise.

C doesn't have user-defined operator overloading. Like many
languages, it overloads the predefined operators on its own predefined
types.
Ah. Okay, but C does support a very limited form of
user-defined overloading for some operators. For example,
the user can apply the () operator to function pointer
types not listed in the Standard.

In other words, "I know what you mean, and you know
what you mean, but we're both having a hard time expressing
it exactly." ;-)
If this "qfloat" were part of the C language, presumably there would
be language-defined overloaded operators for it, just as there are for
any other language-defined floating-point type. But it isn't; it's an
extension implemented by a certain compiler that jacob keeps trying to
advertise here.
From the dribs and drabs of information he's trumpeted
so often, I think Jacob has probably done his "qfloat" in the
form of a Standard-conforming extension, that is, something
that doesn't interfere with a conforming program. I don't
know the specifics of his choices, but if I were going to
add such an extension I'd add a `_qfloat' keyword (in the
implementation' s name space), and maybe a <qfloat.hhead er
that (among other things) did `typedef _qfloat qfloat;'.

Assuming that qfloat is really _qfloat behind the scenes,
I think the extended compiler is within its rights to define
how this extended type responds to various operators. That
is, "implemento r-defined operator overloading" seems legal,
if applied to implementor-defined extended types. The
situation with mixed types is a little murkier because of the
Standard's enumeration of promotion rules; I'm not sure that

_qfloat q = 6;
q *= 7;

.... would be a legal way to obtain forty-two, because the
Standard describes all the possible promotions of the int
operand 7, and none of them leads to a _qfloat value. But
there may be a loophole somewhere I haven't spotted.

Hmmm... I wonder what his _qfloat constants look like.
It seems to me that a diagnostic is required for 3.14Q0 or
suchlike, even if the compiler also recognizes it as a
highly-precise poor approximation to pi. Maybe the compiler
needs to reject such constructs until <qfloat.hprovid es
the magic `#pragma enable_qfloat'. I suppose such a #pragma
would also offer a way out of the promtion pickle. In fact,
maybe #pragma could take care of the whole business: turning
`qfloat' from an identifier to a keyword (doing away with
the need for `_qfloat'), enabling the recognition of constants,
augmenting the conversion rules, everything.

--
Er*********@sun .com

Aug 11 '06 #78

Eric Sosman wrote:
Keith Thompson wrote On 08/10/06 18:54,:
Eric Sosman <Er*********@su n.comwrites:
>
Off-hand, I cannot think of any C operator that is *not*
overloaded. No, not even the comma operator.

I was insufficiently precise.

C doesn't have user-defined operator overloading. Like many
languages, it overloads the predefined operators on its own predefined
types.

Ah. Okay, but C does support a very limited form of
user-defined overloading for some operators. For example,
the user can apply the () operator to function pointer
types not listed in the Standard.
There's still only one semantic for function call. The
operator is overloaded, but not user-defined overloading,
because the semantics can't be changed. Array indexing is
another overloaded operator; also not user-defined overloading.
In other words, "I know what you mean, and you know
what you mean, but we're both having a hard time expressing
it exactly." ;-)
The key is a user having the ability to choose different
semantics based on operand types. If the language chooses, it
isn't user-defined.

Aug 12 '06 #79

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

Similar topics

0
1330
by: C. Barnes | last post by:
Summary: Sorts strings in a way that seems natural to humans. If the strings contain integers, then the integers are ordered numerically. For example, sorts into the order . Code:
3
1750
by: Derek Basch | last post by:
Hello All, I need to sort a list using an unnatural sequence. I have a list like so: foo = print foo.sort()
1
2431
by: Connelly Barnes | last post by:
Summary: Sorts strings in a way that seems natural to humans. If the strings contain integers, then the integers are ordered numerically. For example, sorts into the order . Code: #---------------------------------------------------------
4
2199
by: Andrew E | last post by:
Hi all I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines: ./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20 etc However, I'd like to add a mode that will handle, say:
7
1885
by: tommaso.gastaldi | last post by:
This is a curious question. I'd like to know your opinion. I am attaching a drawing resize to a mouse wheel event. Frankly, to me was most natural that, if I mouse wheel UP, the shape gets bigger, while it gets smaller when mouse wheel DOWN. I just noticed that Photoshop does the opposite. Any though about the most natural way (or perhaps are both "natural") ?
1
1766
by: Hendri Adriaens | last post by:
Hi, I have an onmouseover script that displays a div with some comment. There are several links getting this onmouseover functionality, all with their own comment text. Now I want the div to have a max width, but if the natural width is smaller than the max width, it should get the natural width. commentObj is the div and commentObj.offsetWidth returns the natural width, as long as we didn't set it to anything else (it seems). As soon as...
1
2639
by: Steven Bird | last post by:
NLTK — the Natural Language Toolkit — is a suite of open source Python modules, data sets and tutorials supporting research and development in natural language processing. It comes with 50k lines of code, 300Mb of datasets, and a 360 page book which teaches both Python and Natural Language Processing. NLTK has been adopted in at least 40 university courses. NLTK is hosted on sourceforge, and is ranked in the top 200 projects. ...
3
4325
by: anon538 | last post by:
I am creating an application that has to check for natural numbers. By natural numbers, I mean positive whole numbers. //natural needs to equal 1,2,3, etc. if(minutes % 60 == natural) { minuteField.value = minutes; } How can I can I do this? Thanks.
10
8086
by: Ben | last post by:
Hi at all I am looking for the natural size of an image I found this function : while ((imgHeight = image.getHeight(this)) == -1 ) { // loop until image loaded
0
9997
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
9845
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
11279
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...
1
10981
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
10499
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7205
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();...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4306
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.