java - Does C have a concept of primitive types and if so what are they? - Stack Overflow
What is meant by a primitive data type? - Software Engineering Stack Exchange
Why do data types like "char" , "int" or "long" are called primitive, when they are all made up of binary? Technically, isn't all non-binary data "non primitive / composite"?
Primitive vs User Defined vs Abstract Data Type, what's the delta?
Videos
The answer is no, and for 2 reasons.
- The notion of primitive types in Java exists by opposition to object types. This has no sense in C which is not an object language.
- C intends to be as efficient as possible on any architecture, from 16 or even 8 bits microcontrollers to 64 bits platforms. For that reason the
inttype is generally chosen as the natural type for the architecture provided it contains at least 16 bits. On the other hand, Jave targets maximum portability and fixes the size of all its types.
So even if the list on Wikipedia looks large, it is (unfortunately...) accurate.
C appears to have many, many types, but what if any are considered primitive types.
The Java term "primitive type" distinguishes from reference types. C has no direct analog of Java's reference types, so no need to draw such a distinction.
C does, however, define several categories of types, and among those, the basic types are a reasonably good analogue of Java's primitive types. This category comprises char, the signed and unsigned integer types, and the floating[-point] types. It is ultimately from these, the enumerated types, and type void that all other types are derived, including array types, structure and union types, pointer types, atomic types, and function types.
The basic types can include implementation-defined types, and therefore cannot be exhaustively listed, but those defined by the language spec are:
char
The standard signed integer types
signed char, short int, int, long int, long long int
The standard unsigned integer types
_Bool, unsigned char, unsigned short int, unsigned int, unsigned long int, unsigned long long int
The real floating types
float, double, long double
The complex types
float _Complex, double _Complex, long double _Complex
This is covered in section 6.2.5 of the language spec.
It should be noted that whereas Java specifies the the size and representation of its primitive types, C leaves some of those details of its basic types to implementations, placing constraints on their ranges of representable values and other properties without specifying exact details.
C appears to have many, many types
C has an unbounded number of types, as it provides for types to be derived from other types. The same applies to Java. Ignoring implementation-defined extension types, C has more than twice as many basic types as Java has primitive types, but that's still manageable, especially given the way they are organized.
However, C also has a mechanism for defining type aliases, and a whole family of standard type aliases, and these can make it appear that there are more types than really there are.
It kind of depends on the language.
For example, in languages like C and C++, you have a number of built-in scalar types - int, float, double, char, etc. These are "primitive" in the sense that they cannot be decomposed into simpler components. From these basic types you can define new types - pointer types, array types, struct types, union types, etc.
Then you have a language like old-school Lisp, where everything is either an atom or a list. Again, by the above definition, an atom is "primitive" in the sense that it cannot be decomposed into something simpler.
Edit
As far as I'm concerned, the terms "primitive", "basic", and "built-in" are pretty much interchangeable. If you want to get really pedantic, though, you can distinguish between types that are "built-in" (those explicitly provided by the language definition) and types derived from the built-in types that are still "primitive" or "basic" in that they cannot be decomposed into simpler elements. C's typedef facility allows you to create new type names for existing types. Ada allows you to create new scalar types that have constraints on them. For example, you can derive a Latitude type from the built-in floating type, with the constraint that it can't take on values outside the range [-90.0, 90.0]. It's still a primitive or basic type in that it cannot be broken down into any simpler components, but since it's user-defined, it's not considered a "built-in" type.
Again, these concepts are a little fuzzy, and it really depends on context. For example, the notion of a "built-in" type is meaningless for a typeless language like BLISS.
From the Java perspective:
In Java, there is a very clear distinction between primitive and non-primitive types.
A variable of a primitive type directly contains the value of that type (in other words, they are value types).
A variable of a non-primitive type doesn't contain the value directly; instead, it is a reference (similar to a pointer) to an object. (It is not possible in Java to create user-defined value types).
Java has eight primitive types: byte, short, int, long, char, boolean, float and double. Anything else is a non-primitive type.