Talk:C data types

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject C/C++ (Rated Start-class, High-importance)
WikiProject icon This article is within the scope of WikiProject C/C++, a collaborative effort to improve the coverage of C/C++ on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the quality scale.
 High  This article has been rated as High-importance on the importance scale.
Taskforce icon
This article falls within the scope of C.
 

Missing Information[edit]

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.

68.54.162.15 (talk) 08:33, 30 June 2012 (UTC)

1.2 Size[edit]

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

If no one disagrees within a few days, I'll change those three sentences to similar statements as above and add a reference. --66.41.31.76 (talk) 08:19, 22 September 2008 (UTC)

No: Those statements are correct. Many C compilers use a 32-bit int nowadays (which is more than 16 bits). The current C standard says (emphasis added):

5.2.4.2.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
Alksentrs (talk) 14:58, 23 September 2008 (UTC)

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.

Perhaps a separate table should be introduced that explicitly states the range of values available for each of the variable types.
--66.41.31.76 (talk) 06:38, 24 September 2008 (UTC)

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
  • correct
  • 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.

80.162.60.16 (talk) 12:46, 14 January 2012 (UTC)

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.

213.247.248.50 (talk) 02:44, 10 June 2013 (UTC)

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,

'ISO/IEC 9899:2011

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 (talkcontribs) 08:42, 9 September 2014 (UTC)

Variable types[edit]

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)

type qualifiers[edit]

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 84.163.217.217 (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[edit]

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.

ALbert Mietus // http:albert.mietus.nl —The preceding unsigned comment was added by 62.177.151.49 (talk) 07:41, 2 April 2007 (UTC).

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)

Forgetting something[edit]

Also needs to include struct, union and enum. http://en.wikipedia.org/wiki/C_syntax has some info on these. —Preceding unsigned comment added by 119.224.35.68 (talk) 00:32, 31 January 2010 (UTC)

Typical sizeof(long double) should include 16[edit]

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 88.165.171.247 (talk) 13:57, 24 March 2011 (UTC)

Relevant keywords[edit]

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! 130.237.57.80 (talk) 15:54, 9 March 2011 (UTC)

See C syntax. --RokerHRO (talk) 16:57, 12 August 2012 (UTC)

inttypes.h[edit]

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[edit]

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?[edit]

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.

— Preceding unsigned comment added by 81.186.243.41 (talk) 15:37, 26 January 2013 (UTC)

I'd like to restructure the article so it matches the ISO C standard[edit]

The ISO C standard describes 3 categories of types:

  1. object types
  2. function types
  3. 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)