473,799 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Classification of arithmetic types

As Richard Bos rightly pointed out, I had left in my classification
of types the C99 types Complex and boolean. Here is a new
classification. Those are not mentioned in the classification
of Plauger and Brody, probably because their work predates
C99. Since there are no examples of this in the literature
(known to me) please take a look.

Thanks
3.1.1 Arithmetic types
3.1.1.1 Integer types
3.1.1.1.1 Specific integer types
3.1.1.1.1.1 boolean type
3.1.1.1.1.2 char (signed/unsigned)
3.1.1.1.1.3 short (signed unsigned)
3.1.1.1.1.4 int (signed/unsigned)
3.1.1.1.1.5 long (signed/unsigned)
3.1.1.1.1.6 long long (signed/unsigned)
3.1.1.1.2 Bitfields (signed/unsigned)
3.1.1.1.3 Enumeration types
3.1.1.2 Floating types
3.1.1.2.1 Real types
3.1.1.2.1.1 float
3.1.1.2.1.2 double
3.1.1.2.1.3 long double
3.1.1.2.4 Complex types
3.1.1.2.4.1 float Complex
3.1.1.2.4.2 double Complex
3.1.1.2.4.2 long double Complex

I would define arithmetic types as those that define the 4 operations.
This distiguishes them from pointer types where addition and
subtraction are defined but not multiplication/division.

Is that correct?

jacob
Dec 11 '06
27 2058
jacob navia <ja***@jacob.re mcomp.frwrites:
[...]
I would define arithmetic types as those that define the 4 operations.
This distiguishes them from pointer types where addition and
subtraction are defined but not multiplication/division.

Is that correct?
You don't get to define "arithmetic types". The term is defined in
C99 6.2.5p18. (I believe your definition happens to match the
standard's definition.)

Read C99 6.2.5 before you speculate.

--
Keith Thompson (The_Other_Keit h) 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.
Dec 11 '06 #11
Keith Thompson a écrit :
jacob navia <ja***@jacob.re mcomp.frwrites:
[...]
>>I would define arithmetic types as those that define the 4 operations.
This distiguishes them from pointer types where addition and
subtraction are defined but not multiplication/division.

Is that correct?


You don't get to define "arithmetic types". The term is defined in
C99 6.2.5p18. (I believe your definition happens to match the
standard's definition.)

Read C99 6.2.5 before you speculate.
The standard just says:

"Integer and floating types are collectively called arithmetic types."

This definition is just an enumeration, not a functional
definition, that I would prefer.

But this is not very important since the end result is the same.
Dec 11 '06 #12
Keith Thompson a écrit :
jacob navia <ja***@jacob.re mcomp.frwrites:
>>The same applies to chart ("plain" char) since it is defined either
as unsigned or signed char, what means it is not another basic
type but a synonym for one of the char types.


No, type char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them.
Mmmmm

" char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them" ...

I have some difficulty following you here. If it has the same
characteristics then is the same! How can a type
have the same characteristics (and name) and still be different?

long and int are different types since long can be longer than int,
even if in many implementations long == int. OK.

But char can never have a different size than one of the
signed/unsigned char types so IT IS the same...
This usually
doesn't matter due to implicit conversions, but these types:

char*
unsigned char*
signed char*

are all incompatible; values of these types cannot be assigned to each
other without a cast. If char were an alias for either signed char or
unsigned char, this would not be the case. (Does lcc-win32 get this
right?)
Dunno. Char is signed by default.

Dec 11 '06 #13
jacob navia wrote:
Keith Thompson a écrit :
jacob navia <ja***@jacob.re mcomp.frwrites:
>The same applies to chart ("plain" char) since it is defined either
as unsigned or signed char, what means it is not another basic
type but a synonym for one of the char types.

No, type char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them.

Mmmmm

" char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them" ...

I have some difficulty following you here. If it has the same
characteristics then is the same! How can a type
have the same characteristics (and name) and still be different?
#include <limits.h>

#if CHAR_MIN < 0
typedef signed char plain_char;
#else
typedef unsigned char plain_char;
#endif

plain_char *a;
/* really plain */ char *b;

int main(void) {
a = b; /* disallowed */
b = a; /* disallowed */
}

If char were the same type as (un)signed char, this would be allowed.

Dec 11 '06 #14
"jacob navia" <ja***@jacob.re mcomp.frwrote in message
news:45******** ******@jacob.re mcomp.fr...
Keith Thompson a écrit :
>jacob navia <ja***@jacob.re mcomp.frwrites:
>>>The same applies to chart ("plain" char) since it is defined either
as unsigned or signed char, what means it is not another basic
type but a synonym for one of the char types.


No, type char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them.

Mmmmm

" char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them" ...

I have some difficulty following you here. If it has the same
characteristics then is the same! How can a type
have the same characteristics (and name) and still be different?
The proper term, instead of "characteristic s", is "representation ".
It is often true in C that two types have the same representation
but are nevertheless considered by the compiler to be distinct
types. char/signed char or char/unsigned char is just one of these
pairs.
long and int are different types since long can be longer than int,
even if in many implementations long == int. OK.

But char can never have a different size than one of the
signed/unsigned char types so IT IS the same...
The same representation, yes.
>This usually
doesn't matter due to implicit conversions, but these types:

char*
unsigned char*
signed char*

are all incompatible; values of these types cannot be assigned to each
other without a cast. If char were an alias for either signed char or
unsigned char, this would not be the case. (Does lcc-win32 get this
right?)

Dunno. Char is signed by default.
Sez who?

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Dec 11 '06 #15
"jacob navia" <ja***@jacob.re mcomp.frwrote in message
news:45******** *************** @news.orange.fr ...
P.J. Plauger a écrit :
>"Eric Sosman" <es*****@acm-dot-org.invalidwrot e in message
news:8o******* *************** ********@comcas t.com...

>>>jacob navia wrote:

As Richard Bos rightly pointed out, I had left in my classification
of types the C99 types Complex and boolean. Here is a new
classificat ion. Those are not mentioned in the classification
of Plauger and Brody, probably because their work predates
C99. Since there are no examples of this in the literature
(known to me) please take a look.


For an update of the Plauger & Brodie documentation, see the C
portion of our on-line manual:

http://www.dinkumware.com/manuals/

>>>>3.1.1 Arithmetic types
3.1.1.1 Integer types
3.1.1.1.1 Specific integer types
3.1.1.1.1.1 boolean type
3.1.1.1.1.2 char (signed/unsigned)

Also "plain old char," a third type distinct from the other
two (even though it behaves identically to one of them).
3.1.1.1.1.3 short (signed unsigned)
3.1.1.1.1.4 int (signed/unsigned)
3.1.1.1.1.5 long (signed/unsigned)
3.1.1.1.1.6 long long (signed/unsigned)

How about wchar_t, size_t, ptrdiff_t, sig_atomic_t, wint_t,
and the <stdint.htype s?
3.1.1.1.2 Bitfields (signed/unsigned)
3.1.1.1.3 Enumeration types
3.1.1.2 Floating types
3.1.1.2.1 Real types
3.1.1.2.1.1 float
3.1.1.2.1.2 double
3.1.1.2.1.3 long double

float_t and double_t?
3.1.1.2.4 Complex types
3.1.1.2.4.1 float Complex
3.1.1.2.4.2 double Complex
3.1.1.2.4.2 long double Complex

time_t, clock_t, wctrans_t, and wctype_t are difficult to
categorize .


What the standard says about each of these types is summarized
in our manual.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


Thanks for your answer Mr Plauger but I could not find that type
classification there. Maybe you would give a more specific link?
I browsed a lot of C stuff (and C++ stuff) but could not find it.
We don't include the language portion of P&B in our latest manual,
since it's a pure library manual as much as possible. But you'll
find descriptions of the constraints on:

-- wchar_t, size_t, ptrdiff_t, sig_atomic_t, wint_t, and the
<stdint.htype s

-- time_t, clock_t, wctrans_t, and wctype_t

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Dec 11 '06 #16
On Mon, 11 Dec 2006 15:46:01 +0100, in comp.lang.c , jacob navia
<ja***@jacob.re mcomp.frwrote:
>As far as I understood this stuff, all those are defined in terms of
one of the primitive types in the enumeration above.
For instance, in many implementations size_t is unsigned long,
or time_t is long long, or clock_t is int, etc etc.
In fact the standard _doesn't_ say they have to be synonyms to any
other type.

For instance clock_t and time_t merely have to be arithmetic, so it
could be a a 2560-bit double (7.23), irrespective of whether a long
double were 32, 64, 80 or 128 bits. Size_t has to be an unsigned
integer type - but again there's no restriction on width (7.17) so it
could be wider than long long. In fact such designs might actually
make sense - using an integer type for time _is_ kinda daft, while
size_t needs to be able to refer to all possible availalbe memory..
>The same applies to chart ("plain" char) since it is defined either
as unsigned or signed char, what means it is not another basic
type but a synonym for one of the char types.
The C standard does explicitly say that its a distinct type
(6.2.5p15).
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Dec 11 '06 #17
jacob navia <ja***@jacob.re mcomp.frwrites:
Keith Thompson a écrit :
>jacob navia <ja***@jacob.re mcomp.frwrites:
>>>The same applies to chart ("plain" char) since it is defined either
as unsigned or signed char, what means it is not another basic
type but a synonym for one of the char types.
No, type char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them.

Mmmmm

" char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them" ...

I have some difficulty following you here. If it has the same
characteristics then is the same!
Um, no.
How can a type
have the same characteristics (and name) and still be different?
By having the same characteristics (*not* the same name) and still
being different. What's unclear about that?
long and int are different types since long can be longer than int,
even if in many implementations long == int. OK.
Right, assuming that "long == int" is a shorthand for "long and int
have the same range and size".

int* and float* may very well have exactly the same characteristics
(representation , alignment, etc.), but they're distinct types.

long and int are distinct types even if they happen to have the same
properties. It's exactly the same for char and signed char, and for
char and unsigned char.
But char can never have a different size than one of the
signed/unsigned char types so IT IS the same...
No, they're distinct types (that happen to have the same size). Are
you arguing that size is the only thing that determines whether two
types are the same? It isn't.

C99 6.2.5p15:

The three types char, signed char, and unsigned char are
collectively called the _character types_. The implementation
shall define char to have the same range, representation, and
behavior as either signed char or unsigned char.

with a footnote:

CHAR_MIN, defined in <limits.h>, will have one of the values 0 or
SCHAR_MIN, and this can be used to distinguish the two
options. Irrespective of the choice made, char is a separate type
from the other two and is not compatible with either.
>This usually
doesn't matter due to implicit conversions, but these types:
char*
unsigned char*
signed char*
are all incompatible; values of these types cannot be assigned to
each
other without a cast. If char were an alias for either signed char or
unsigned char, this would not be the case. (Does lcc-win32 get this
right?)

Dunno. Char is signed by default.
Try compiling this:

#include <limits.h>
int main(void)
{
char *cp;
unsigned char *up;
signed char *sp;

#if CHAR_MIN == 0
/* plain char is unsigned */
cp = up; /* constraint violation */
#else
/* plain char is signed */
cp = sp; /* constraint violation */
#endif
return 0;
}

A conforming compiler must issue a diagnostic for whichever assignment
is not deleted by the preprocessor. (If the diagnostic includes a
line number, it will tell you whether plain char is signed or
unsigned.) What does lcc-win32 do (in conforming mode)?

--
Keith Thompson (The_Other_Keit h) 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.
Dec 11 '06 #18
"P.J. Plauger" <pj*@dinkumware .comwrites:
"jacob navia" <ja***@jacob.re mcomp.frwrote in message
news:45******** ******@jacob.re mcomp.fr...
>Keith Thompson a écrit :
[...]
>>If char were an alias for either signed char or unsigned char,
this would not be the case. (Does lcc-win32 get this right?)

Dunno. Char is signed by default.

Sez who?
Sez lcc-win32, presumably, since I had just asked him a question about
it.

--
Keith Thompson (The_Other_Keit h) 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.
Dec 11 '06 #19
"P.J. Plauger" <pj*@dinkumware .comwrites:
"jacob navia" <ja***@jacob.re mcomp.frwrote in message
news:45******** ******@jacob.re mcomp.fr...
>Keith Thompson a écrit :
>>jacob navia <ja***@jacob.re mcomp.frwrites:

The same applies to chart ("plain" char) since it is defined either
as unsigned or signed char, what means it is not another basic
type but a synonym for one of the char types.
No, type char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them.

Mmmmm

" char is distinct from both signed char and unsigned char,
though it has the same characteristics as one of them" ...

I have some difficulty following you here. If it has the same
characteristic s then is the same! How can a type
have the same characteristics (and name) and still be different?

The proper term, instead of "characteristic s", is "representation ".
It is often true in C that two types have the same representation
but are nevertheless considered by the compiler to be distinct
types. char/signed char or char/unsigned char is just one of these
pairs.
[...]

I used the more general term "characteristic s" because there's more to
it than just the representation. Plain char and (signed|unsigne d)
char have the same representation, alignment, minimum and maximum
valiues, and probably some other things I haven't thought of. Or are
all those things considered part of the "representation "?

Plain char and (signed|unsigne d) char are identical in all respects
*except* that they have different names and are distinct types.

--
Keith Thompson (The_Other_Keit h) 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.
Dec 11 '06 #20

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

Similar topics

5
2849
by: Lionel B | last post by:
Greetings, I am trying to implement "element-wise" arithmetic operators for a class along the following lines (this is a simplified example): // ----- BEGIN CODE ----- struct X { int a,b;
16
5145
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
4
1556
by: PDHB | last post by:
I'm sorry, but this is just the height of stupidity. I love the dot net framework. It has actually been sufficient to convert an anti-microsoft extremist (myself) to the windows camp. But not having numerical value types inherit from an interface to allow for arithmetic in generics, or in some other way allow arithmetic in generics without a performance killing or ugly work around is just the epitomy of idiocy. Yes, microsoft today is...
2
5125
by: Frederick Gotham | last post by:
I just want to clarify my understanding of arithmetic and comparison between two different integer types. Phase (1): Integer Promotion ---------- All of the following types always get promoted to "signed int": signed char
26
3065
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I read some of the items from the bottom up of the buffer, and some from the top down, moving the bottom items back to the new re-allocated bottom on every file read. Then when I've read all four files, I sort the top and bottom items separately...
6
13832
by: sarathy | last post by:
Hi, What is integer promotion? How is it different from arithmetic conversion? Regards, Sarathy
6
1645
by: Grant Robertson | last post by:
I am interested in including classification info in metadata. I am aware of the Dublin Core and XMP. However, neither of these appear to specify exactly how the classification data should be formatted within the element. I am interested in any standardized formats for expressing Dewey Decimal System - DDS, Library of Congress Classification - LCC, Cutter Expansive Classification, Universal Decimal Classification - UDC, Colon Notation...
4
1945
by: Evan Klitzke | last post by:
Hi all, What frameworks are there available for doing pattern classification? I'm generally interested in the problem of mapping some sort of input to one or more categories. For example, I want to be able to solve problems like taking text and applying one or more tags to it like "romance", "horror", "poetry", etc. This isn't really my research specialty, but my understanding is that Bayesian classifiers are generally used for problems...
0
9689
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
9550
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
10495
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
10248
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
10032
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
6811
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
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
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 we have to send another system
3
2942
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.