I am reading Programming in C by Stephan G. Kochan
. He states that C has only five data types; int
, float
, double
, char
and _Bool
.
我正在阅读Stephan G. Kochan的C编程。他说C只有五种数据类型; int,float,double,char和_Bool。
What about long
? Isn't it a builtin type? http://www.programiz.com/c-programming/c-data-types says long
is a qualifier to modify the size. If it is a qualifier then it should be only used as a long int
, and not as a standalone long
.
怎么样?它不是内置类型吗? http://www.programiz.com/c-programming/c-data-types说long是修改大小的限定符。如果它是一个限定符,那么它应该只用作long int,而不是一个独立的long。
And what about _Bool
? Many Internet tutorials say there is no boolean type in C.
那么_Bool呢?许多互联网教程都说C中没有布尔类型。
Related:
有关:
-
C长型是多久?
-
Is "long long" = "long long int" = "long int long" = "int long long"?
是“long long”=“long long int”=“long int long”=“int long long”?
3 个解决方案
#1
37
He states that C has only five data types; int, float, double, char and _Bool.
他说C只有五种数据类型; int,float,double,char和_Bool。
That's quite an over-simplification. Maybe intentional, if the book is aimed towards beginners.
这简直过分了。也许是故意的,如果这本书是针对初学者的。
If you go through C11 6.2.5 it lists the following distinct data types:
如果您通过C11 6.2.5,它列出了以下不同的数据类型:
Character types (6.2.5/15)
字符类型(6.2.5 / 15)
char
signed char
unsigned char
Standard signed integer types (6.2.5/4)
标准有符号整数类型(6.2.5 / 4)
signed char
short int
int
long int
long long int
Standard unsigned integer types (6.2.5/5)
标准无符号整数类型(6.2.5 / 5)
_Bool
unsigned char
unsigned short int
unsigned int
unsigned long int
unsigned long long int
Real floating types (6.2.5/10)
真正的浮动类型(6.2.5 / 10)
float
double
long double
Complex types (6.2.5/11)
复杂类型(6.2.5 / 11)
float _Complex
double _Complex
long double _Complex
Enumerated type (6.2.5/16)
枚举类型(6.2.5 / 16)
enum {}
void type (6.2.5/19) (void type is an incomplete type)
void type(6.2.5 / 19)(void类型是不完整的类型)
void
Derived types (6.2.5/20)
派生类型(6.2.5 / 20)
- Array type
- 数组类型
- Structure type
- 结构类型
- Union type
- 联盟类型
- Function type
- 功能类型
- Pointer type
- 指针类型
- Atomic type
- 原子类型
Formally the term is type specifier 6.7.2:
正式的术语是类型说明符6.7.2:
type-specifier:
void
char
short
int
long
float
double
signed
unsigned
_Bool
_Complex
atomic-type-specifier
struct-or-union-specifier
enum-specifier
typedef-name
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
— void
— char
— signed char
— unsigned char
— short, signed short, short int, or signed short int
— unsigned short, or unsigned short int
— int, signed, or signed int
— unsigned, or unsigned int
— long, signed long, long int, or signed long int
— unsigned long, or unsigned long int
— long long, signed long long, long long int, or signed long long int
— unsigned long long, or unsigned long long int
— float
— double
— long double
— _Bool
— float _Complex
— double _Complex
— long double _Complex
— atomic type specifier
— struct or union specifier
— enum specifier
— typedef name每个声明中的声明说明符中应至少给出一个类型说明符,并在每个结构声明和类型名称的说明符限定符列表中给出。每个类型说明符列表应为以下多个集合之一(用逗号分隔,每个项目有多个多集);类型说明符可以按任何顺序出现,可能与其他声明说明符混合。 - void - char - signed char - unsigned char - short,signed short,short int或signed short int - unsigned short,或unsigned short int - int,signed或signed int - unsigned,或unsigned int - long,signed long ,long int或signed long int - unsigned long,或unsigned long int - long long,signed long long,long long int,或signed long long int - unsigned long long,或unsigned long long int - float - double - long double - _Bool - float _Complex - double _Complex - long double _Complex - 原子类型说明符 - struct或union说明符 - enum说明符 - typedef名称
As we can see, long
is a type specifier. It is not a type qualifier.
我们可以看到,long是一个类型说明符。它不是类型限定符。
#2
19
From the C11 draft, section 6.2.5 ("Types)" paragraph 4:
从C11草案第6.2.5节(“类型”)第4段:
There are five standard signed integer types, designated as
signed char
,short int
,int
,long int
, andlong long int
.有五种标准的有符号整数类型,指定为signed char,short int,int,long int和long long int。
How these types are specified in program text is another issue, there are many ways since the syntax is rather lax. For instance, according to 6.7.2 ("Type Specifiers") the following are all valid ways to specify the same type:
如何在程序文本中指定这些类型是另一个问题,因为语法相当宽松,所以有很多方法。例如,根据6.7.2(“类型说明符”),以下是指定相同类型的所有有效方法:
long
,signed long
,long int
, orsigned long int
long,signed long,long int或signed long int
This says that long
by itself is a valid type specifier for the type long int
. This was the same in C99 (and, I would guess, earlier standards too). So no, it's not a qualifier.
这说明long本身就是long int类型的有效类型说明符。在C99中也是如此(我猜,早期的标准也是如此)。所以不,这不是一个限定词。
In addition, the above can be intermixed with things like static
, volatile
, pointer asterisks, and so on.
另外,上面可以混合使用静态,易失性,指针星号等内容。
I would suggest reading some other book, since it's confusing to read books that use different terminology from the standard. The standard is often refered to when answering questions about C, so it's a good idea to be familiar with it.
我建议阅读其他一些书,因为阅读使用与标准不同的术语的书籍令人困惑。在回答有关C的问题时,通常会提到该标准,因此熟悉它是个好主意。
#3
0
In the C programming language, data types are declarations for memory locations or variables that determine the characteristics of the data that may be stored and the methods (operations) of processing that are permitted involving them.
在C编程语言中,数据类型是内存位置或变量的声明,用于确定可以存储的数据的特征以及允许涉及它们的处理方法(操作)。
The C language provides basic arithmetic types, such as integer and real number types, and syntax to build array and compound types. Several headers in the C standard library contain definitions of support types, that have additional properties, such as providing storage with an exact size, independent of the implementation. https://wikipedia.org/wiki/C_data_types
C语言提供基本的算术类型,例如整数和实数类型,以及构建数组和复合类型的语法。 C标准库中的几个标头包含支持类型的定义,这些定义具有其他属性,例如提供具有精确大小的存储,与实现无关。 https://wikipedia.org/wiki/C_data_types
#1
37
He states that C has only five data types; int, float, double, char and _Bool.
他说C只有五种数据类型; int,float,double,char和_Bool。
That's quite an over-simplification. Maybe intentional, if the book is aimed towards beginners.
这简直过分了。也许是故意的,如果这本书是针对初学者的。
If you go through C11 6.2.5 it lists the following distinct data types:
如果您通过C11 6.2.5,它列出了以下不同的数据类型:
Character types (6.2.5/15)
字符类型(6.2.5 / 15)
char
signed char
unsigned char
Standard signed integer types (6.2.5/4)
标准有符号整数类型(6.2.5 / 4)
signed char
short int
int
long int
long long int
Standard unsigned integer types (6.2.5/5)
标准无符号整数类型(6.2.5 / 5)
_Bool
unsigned char
unsigned short int
unsigned int
unsigned long int
unsigned long long int
Real floating types (6.2.5/10)
真正的浮动类型(6.2.5 / 10)
float
double
long double
Complex types (6.2.5/11)
复杂类型(6.2.5 / 11)
float _Complex
double _Complex
long double _Complex
Enumerated type (6.2.5/16)
枚举类型(6.2.5 / 16)
enum {}
void type (6.2.5/19) (void type is an incomplete type)
void type(6.2.5 / 19)(void类型是不完整的类型)
void
Derived types (6.2.5/20)
派生类型(6.2.5 / 20)
- Array type
- 数组类型
- Structure type
- 结构类型
- Union type
- 联盟类型
- Function type
- 功能类型
- Pointer type
- 指针类型
- Atomic type
- 原子类型
Formally the term is type specifier 6.7.2:
正式的术语是类型说明符6.7.2:
type-specifier:
void
char
short
int
long
float
double
signed
unsigned
_Bool
_Complex
atomic-type-specifier
struct-or-union-specifier
enum-specifier
typedef-name
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
— void
— char
— signed char
— unsigned char
— short, signed short, short int, or signed short int
— unsigned short, or unsigned short int
— int, signed, or signed int
— unsigned, or unsigned int
— long, signed long, long int, or signed long int
— unsigned long, or unsigned long int
— long long, signed long long, long long int, or signed long long int
— unsigned long long, or unsigned long long int
— float
— double
— long double
— _Bool
— float _Complex
— double _Complex
— long double _Complex
— atomic type specifier
— struct or union specifier
— enum specifier
— typedef name每个声明中的声明说明符中应至少给出一个类型说明符,并在每个结构声明和类型名称的说明符限定符列表中给出。每个类型说明符列表应为以下多个集合之一(用逗号分隔,每个项目有多个多集);类型说明符可以按任何顺序出现,可能与其他声明说明符混合。 - void - char - signed char - unsigned char - short,signed short,short int或signed short int - unsigned short,或unsigned short int - int,signed或signed int - unsigned,或unsigned int - long,signed long ,long int或signed long int - unsigned long,或unsigned long int - long long,signed long long,long long int,或signed long long int - unsigned long long,或unsigned long long int - float - double - long double - _Bool - float _Complex - double _Complex - long double _Complex - 原子类型说明符 - struct或union说明符 - enum说明符 - typedef名称
As we can see, long
is a type specifier. It is not a type qualifier.
我们可以看到,long是一个类型说明符。它不是类型限定符。
#2
19
From the C11 draft, section 6.2.5 ("Types)" paragraph 4:
从C11草案第6.2.5节(“类型”)第4段:
There are five standard signed integer types, designated as
signed char
,short int
,int
,long int
, andlong long int
.有五种标准的有符号整数类型,指定为signed char,short int,int,long int和long long int。
How these types are specified in program text is another issue, there are many ways since the syntax is rather lax. For instance, according to 6.7.2 ("Type Specifiers") the following are all valid ways to specify the same type:
如何在程序文本中指定这些类型是另一个问题,因为语法相当宽松,所以有很多方法。例如,根据6.7.2(“类型说明符”),以下是指定相同类型的所有有效方法:
long
,signed long
,long int
, orsigned long int
long,signed long,long int或signed long int
This says that long
by itself is a valid type specifier for the type long int
. This was the same in C99 (and, I would guess, earlier standards too). So no, it's not a qualifier.
这说明long本身就是long int类型的有效类型说明符。在C99中也是如此(我猜,早期的标准也是如此)。所以不,这不是一个限定词。
In addition, the above can be intermixed with things like static
, volatile
, pointer asterisks, and so on.
另外,上面可以混合使用静态,易失性,指针星号等内容。
I would suggest reading some other book, since it's confusing to read books that use different terminology from the standard. The standard is often refered to when answering questions about C, so it's a good idea to be familiar with it.
我建议阅读其他一些书,因为阅读使用与标准不同的术语的书籍令人困惑。在回答有关C的问题时,通常会提到该标准,因此熟悉它是个好主意。
#3
0
In the C programming language, data types are declarations for memory locations or variables that determine the characteristics of the data that may be stored and the methods (operations) of processing that are permitted involving them.
在C编程语言中,数据类型是内存位置或变量的声明,用于确定可以存储的数据的特征以及允许涉及它们的处理方法(操作)。
The C language provides basic arithmetic types, such as integer and real number types, and syntax to build array and compound types. Several headers in the C standard library contain definitions of support types, that have additional properties, such as providing storage with an exact size, independent of the implementation. https://wikipedia.org/wiki/C_data_types
C语言提供基本的算术类型,例如整数和实数类型,以及构建数组和复合类型的语法。 C标准库中的几个标头包含支持类型的定义,这些定义具有其他属性,例如提供具有精确大小的存储,与实现无关。 https://wikipedia.org/wiki/C_data_types