Talk:C data types
|This is the talk page for discussing improvements to the C data types article.
This is not a forum for general discussion of the article's subject.
|WikiProject C/C++||(Rated Start-class, High-importance)|
|This article is the subject of an educational assignment supported by Wikipedia Ambassadors through the India Education Program.|
- 1 Missing Information
- 2 1.2 Size
- 3 Variable types
- 4 type qualifiers
- 5 One more type: Boolean
- 6 Forgetting something
- 7 Typical sizeof(long double) should include 16
- 8 Relevant keywords
- 9 inttypes.h
- 10 Move discussion in progress
- 11 What about the basic type void?
- 12 I'd like to restructure the article so it matches the ISO C standard
- 13 anam type: is it bullshit?
I was annoyed to see that a lot of the useful information on this page has been purged. Please compare: http://en.wikipedia.org/w/index.php?title=C_data_types&diff=prev&oldid=456503038
The reason was because it is available on Wiki-Books... Ok, but where is the link to the info? There are two complete *books* on that page, and I was looking specifically for the different pointer/array/function examples (pointer-to-pointer, pointer-to-array, how modifiers fit into that, etc).
If that sort of information doesn't belong on Wikipedia -- fine. But at least link to more information in WikiBooks if that is why the information is being purged.
The following statements are not true:
- An int must be at least 16 bits long
- A long int must be at least 32 bits long.
- A long long int must be at least 64 bits long
A corrected statement would read:
- An int can be up to 16 bits long
- No: Those statements are correct. Many C compilers use a 32-bit
intnowadays (which is more than 16 bits). The current C standard says (emphasis added):
18.104.22.168.1 Sizes of integer types <limits.h>
The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. [...] Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.
- minimum value for an object of type int
- INT_MIN -32767 // −(215 − 1)
- maximum value for an object of type int
- INT_MAX +32767 // 215 − 1
- maximum value for an object of type unsigned int
- UINT_MAX 65535 // 216 − 1
I absolutely agree with your response. However, since the definitions of the variables primarily provides clarification to novice programmers, there should be a clear difference stated between the amount of memory allocated and the range of values that are available to the variable.
For example, a novice could read the statement as saying that int x=1 is a value that is too small, and instead a value that is 16 bits, say int x=0x8000 or larger is necessary. With this in mind, I'm assuming one can see how confusion could result, as there is not an explicit divide made between memory allocation and the available range of values for a variable.
- If a novice programmer thinks that 1 is a value that is too low for an int, said person is either stupid or cannot read and listened to someone who is stupid. The reason why the range of integer types is specified is because a computer may not work with binary bits; a computer could in theory, use ternary logic instead of binary logic: to store the range of 16 binary bits using ternary bits would only require 11 bits (and it would have a greater range). The original statements are
- to the point
- the least confusing it can get without introducing errors or leading new programmers to make even more stupid assumptions about the computer their software will be running on even if they aren't alive when it's being invented.
Is not this sentences exclusive?
The only guarantee is that the long long is not smaller than long, which is not smaller than int, which is not smaller than short.
long long signed integer type. At least 64 bits in size.
- That are two sentences. And they do not contradict each other, they supplement each other. I changed the sentences and hope, they explains it better now. --RokerHRO (talk) 12:41, 9 July 2013 (UTC)
It needs to be removed. The people defending this know it's wrong because they purposefully misquoted it. It states word for word on page 505 under Annex E of both the C99 and C11 draft,
The contents of the header <limits.h> are given below, in alphabetical order. The minimum magnitudes shown shall be replaced by implementation-defined magnitudes with the same sign.
The values stated below that are simply a template. Common sense, why would the standards committee require there to be a 64-bit data type when most processors don't even have 64-bit registers? All the standard says is that long long shall not be smaller than long, which shall not be smaller than int, which shall not be smaller than short, which shall not be smaller than char. The fact that most modern architectures use short/int/long/long long sizes of 16/32/32/64 does not make it the standard. It's perfectly natural for an 8-bit architecture like an 8080 to use short/int/long/long long sizes of 8/8/16/16. The purpose of wiki isn't to hold the hand of a person who can't understand "x is not smaller than y", it's to provide people with facts.
So frustrated right now... This error just wasted hours of my time trying to figure out how to make a C compiler for an 8-bit architecture conform to C11 and you guys have known this was wrong for over 4 years. — Preceding unsigned comment added by DaemonR (talk • contribs) 08:42, 9 September 2014 (UTC)
- A C compiler supplying a long long that is 16 bits DOES NOT conform to C11. Annex E of C11 specifically states that the limits shown in the table are minimum values; the implementation-defined values are allowed to be greater than the values in Annex E, but never smaller. Annex E also states that it is subject to section 22.214.171.124.1, which makes it explicitly clear that the implementation-defined magnitudes shall (normative language) be equal to or greater than the values shown. The language in C99 is the same. 126.96.36.199 (talk) —Preceding undated comment added 14:12, 18 August 2016 (UTC)
It's not true there are 4 basic types; that's just the way you've chosen to introduce them. The C90 standard has more like twelve. You don't mention several other built-in types.
C99 introduces long long, complex and imaginary types, and _Bool.
If you think it's worth covering types properly, I'm happy to help. Akihabara 02:55, 12 July 2005 (UTC)
static is not discussed, and should be. And isn't const also used by compilers when optimizing? If it isn't (i.e. they detect a lack of change on their own) that is interesting enough to mention, IMHO.
- static is not a type qualifier, but a storage class 188.8.131.52 (talk) 17:07, 31 August 2008 (UTC)
If other basic types beyond the basic 5 are mentioned, the time of their introduction (i.e. C99) should be specified. Most books have char, int, float, double, and sometimes void, and lumping "imaginary" in with them would confuse people.
UNIX has programs (cdecl and c++decl) for converting type declarations to and from English.
One more type: Boolean
There is at least one more type: Boolean!
Although it is not possible to declare a variable of that type, the Boolean-type is essential to C! Without it, it would not be possible to write a decent if-statement.
- No. There is no such type in C. If-statements (and the like) test if the condition is nonzero. --Spoon! 08:07, 2 April 2007 (UTC)
- Boolean was introduced in C99, so yes, it does exist, but in C89 it is true that if statements simply check if the test is non-zero or not. --FrederikHertzum 17:40, 15 May 2007 (UTC)
Typical sizeof(long double) should include 16
The table in the Size section lists the typical size in bytes of a (long double) as "8 or 12". I propose changing this to "8, 12, or 16", as 16 is a very common sizeof(long double), as is the case for standard gcc x86-64 on GNU/Linux. --Kamalmostafa (talk) 22:11, 26 November 2010 (UTC) Custom types with typedef! —Preceding unsigned comment added by 184.108.40.206 (talk) 13:57, 24 March 2011 (UTC)
There are common keywords used together with variable declarations, this includes "static", "volatile", "extern", "auto", "register". Would be nice if someone knowledgeable about all the quirky details covered all of them! 220.127.116.11 (talk) 15:54, 9 March 2011 (UTC)
inttypes.h is said to have been merged to this page. However, this page does not seem to have enough information on inttypes.h at least as much as the original page contained. Please fix this.
Jobin (talk) 05:38, 22 October 2011 (UTC)
- I have removed the redirect from inttypes.h and its an article again. I think it should be fixed too, or the article should be merged with limits.h instead. Christian75 (talk) 06:56, 31 October 2011 (UTC)
- Please explain what exactly is not explained in this article that is not also WP:OR. 1exec1 (talk) 14:37, 31 October 2011 (UTC)
- The old page (and/or the <stdint.h> one) had information about which platforms/compilers provide this header. I think that this would be useful information.
- BTW, is there any reason to write inttypes.h and not <inttypes.h> as in the standard? (In the standard, this is important, because inttypes.h denotes a filename, while the <inttypes.h> header doesn't need to be implemented as a file.) Vincent Lefèvre (talk) 13:37, 12 August 2012 (UTC)
Move discussion in progress
There is a move discussion in progress which affects this page. Please participate at Talk:C standard library - Requested move and not in this talk page section. Thank you. —RM bot 09:40, 8 November 2011 (UTC)
What about the basic type void?
It is not mentioned here at all. :-( Even if you cannot declare objects of type
void, this type is used to build-up other types, e.g. pointer or function types. --RokerHRO (talk) 21:47, 26 March 2012 (UTC)
- The C Standard says (6.2.5p19 Types)
The void type comprises an empty set of values; it is an incomplete object type that cannot be completed.
I'd like to restructure the article so it matches the ISO C standard
The ISO C standard describes 3 categories of types:
- object types
- function types
- incomplete types
Than it describes the arithmetical types (
_Bool, integer and floating point types), the derived types (arrays, structures, unions, pointer and function) and finally the so-called "type modifier" (const, volatile, restrict, _Atomic).
Unfortunately there is no clear structure or categorization in the ISO standard. Perhaps there is one in other notable C books, if yes we should use one. What do you think? --RokerHRO (talk) 13:46, 10 June 2015 (UTC)
anam type: is it bullshit?
Type with "anam" were added. But I found nothing about it after a quick search. It seems to be bullshit. A source would be appreciated, otherwise I think that this weird potential type should be removed. — Preceding unsigned comment added by RyDroid (talk • contribs) 17:31, 20 November 2016 (UTC)