C语言类型转换规则好复杂?

CJacky++ 2011-08-27 05:28:04
signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long之间的类型转换,是否遵循以下原则?(size指sizeof(?))
1. size大小相同时(符号不同), 内部存储值不变;
2. 大size转化成小size时,内部存储值截取小size部分,高位部分舍弃;
3. 小size转化为大size时,转化成signed类型,表示值保持不变。如果要转成unsigned,再按第1原则将其转化成unsigned.

请问高手,有没有不符合上面原则的,请举个反例,谢谢。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void TellMem(void * pData, int size)
{
unsigned char * pBuf;

pBuf = (unsigned char *)pData;
while (size--)
{
printf("%02X ", *pBuf);
pBuf++;
}
printf("\n");
}

int main(void)
{
signed char s8;
unsigned char u8;
signed short s16;
unsigned short u16;
signed int s32;
unsigned int u32;

/* size 相同时, 内部存储值不变 */
s8 = -1;
s16 = -1;
s32 = -1;

u8 = s8;
u16 = s16;
u32 = s32;

TellMem(&s8, sizeof(s8)); // FF
TellMem(&u8, sizeof(u8)); // FF
TellMem(&s16, sizeof(s16)); // FF FF
TellMem(&u16, sizeof(u16)); // FF FF
TellMem(&s32, sizeof(s32)); // FF FF FF FF
TellMem(&u32, sizeof(u32)); // FF FF FF FF

s8 = 1;
s16 = 1;
s32 = 1;

u8 = s8;
u16 = s16;
u32 = s32;

TellMem(&s8, sizeof(s8)); // 01
TellMem(&u8, sizeof(u8)); // 01
TellMem(&s16, sizeof(s16)); // 01 00
TellMem(&u16, sizeof(u16)); // 01 00
TellMem(&s32, sizeof(s32)); // 01 00 00 00
TellMem(&u32, sizeof(u32)); // 01 00 00 00

/* 大size转成小size, 内部存储值截取小size部分,高位部分舍弃 */
s32 = 0x12345678;
s16 = s32;
u16 = s32;
s8 = s16;
u8 = s16;
TellMem(&s32, sizeof(s32)); // 78 56 34 12
TellMem(&s16, sizeof(s16)); // 78 56
TellMem(&u16, sizeof(u16)); // 78 56
TellMem(&s8, sizeof(s8)); // 78
TellMem(&u8, sizeof(u8)); // 78
// 小size转化为大size时,转化成signed类型,表示值保持不变。如果要转成unsigned,再按第1原则将其转化成unsigned.
s8 = -1;
s16 = s8;
u16 = s8;
s32 = s16;
u32 = s16;

printf("%d, %d, %d\n", s8, s16, s32); // -1,-1,-1
TellMem(&s8, sizeof(s8)); // FF
TellMem(&s16, sizeof(s16)); // FF FF
TellMem(&u16, sizeof(u16)); // FF FF
TellMem(&s32, sizeof(s32)); // FF FF FF FF
TellMem(&u32, sizeof(u32)); // FF FF FF FF

system("pause");
return 0;
}


...全文
560 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
CJacky++ 2011-08-30
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 0153 的回复:]
好像不用记这么全,只要掌握最关键的一条就可以了:
凡是有符号型发生扩展,都是带符号扩展(即x86下出现movsx指令)
因为只有这条的结果有可能和编程者的实际想法不一致。
[/Quote]
++++
天亮后说晚安 2011-08-29
  • 打赏
  • 举报
回复
有符号型发生扩展,都是带符号扩展
其他应该大赚小
0153 2011-08-29
  • 打赏
  • 举报
回复
好像不用记这么全,只要掌握最关键的一条就可以了:
凡是有符号型发生扩展,都是带符号扩展(即x86下出现movsx指令)
因为只有这条的结果有可能和编程者的实际想法不一致。
赵4老师 2011-08-29
  • 打赏
  • 举报
回复
VC调试(TC或BC用TD调试)时按Alt+8、Alt+6和Alt+5,打开汇编窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应内存和寄存器变化,这样过一遍不就啥都明白了吗。
(Linux或Unix下可以在用GDB调试时,看每句C对应的汇编并单步执行观察相应内存和寄存器变化。)
CJacky++ 2011-08-29
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 supermegaboy 的回复:]
引用 9 楼 cmarquis 的回复:
引用 2 楼 supermegaboy 的回复:
引用楼主 cmarquis 的回复:
signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long之间的类型转换,是否遵循以下原则?(size……
[/Quote]
supermegaboy,能给个不正确例子吗?
CJacky++ 2011-08-28
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 anyidan 的回复:]
还原了又怎样,一不小心还是会错的
[/Quote]
规则越简单越不容易出错。我是想归纳一下,作为以后编程的依据。
CJacky++ 2011-08-28
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 supermegaboy 的回复:]
引用 9 楼 cmarquis 的回复:
引用 2 楼 supermegaboy 的回复:
引用楼主 cmarquis 的回复:
signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long之间的类型转换,是否遵循以下原则?(size……
[/Quote]
能举个反例吗?
CJacky++ 2011-08-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jackyjkchen 的回复:]
没事别乱转,我平均3000行代码出现一次转换
[/Quote]
你说的应该是显式的强制性数据类型转换吧,可是C语言的数据转换无处不在,避无可避的。
显式转换(强制转换): 强制性数据类型转换、利用标准库函数转换
隐式转换(自动转换): 一般算数转换、输出转换(printf)、赋值转换、函数调用转换
AnYidan 2011-08-28
  • 打赏
  • 举报
回复
还原了又怎样,一不小心还是会错的
CJacky++ 2011-08-28
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 ljljlj 的回复:]
轿车的刹车都在右侧,麻烦楼主给找个左侧的。
[/Quote]
你想说什么?
ljhhh0123 2011-08-28
  • 打赏
  • 举报
回复
轿车的刹车都在右侧,麻烦楼主给找个左侧的。
飞天御剑流 2011-08-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 cmarquis 的回复:]
引用 2 楼 supermegaboy 的回复:
引用楼主 cmarquis 的回复:
signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long之间的类型转换,是否遵循以下原则?(size指sizeof(?))
1. size大小……
[/Quote]
你这三条规则都只有部分正确。
CJacky++ 2011-08-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 supermegaboy 的回复:]
引用楼主 cmarquis 的回复:
signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long之间的类型转换,是否遵循以下原则?(size指sizeof(?))
1. size大小相同时(符号不同), 内部存储值不变;
2. 大s……
[/Quote]
那三个规则是我根据资料抽象出来的,那段代码只是验证那三个规则用的一些例子,当然,没有在所有的编译器,验证所有的情形,所以想问一下高手有没有不适用的例子。
看过别人描述转换的规则,太复杂,不好记,我想还原C语言创造者的最初的思路。不知道这三条规则是否适用?有没有反例?
CJacky++ 2011-08-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 supermegaboy 的回复:]
引用楼主 cmarquis 的回复:
signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long之间的类型转换,是否遵循以下原则?(size指sizeof(?))
1. size大小相同时(符号不同), 内部存储值不变;
2. 大s……
那段代码只是验证那三个规则用的。看过别人描述转换的规则,太复杂,不好记,我想还原C语言创造的最初的思路。不知道这三条规则是否适用?有没有反例。
暮雨晨舟 2011-08-27
  • 打赏
  • 举报
回复
不明白 帮顶
飞天御剑流 2011-08-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 luciferisnotsatan 的回复:]
这个不复杂呀,代码写多了自然就知道了。
而且,一般写代码时,都竟然做到类型匹配。而不是在那转来转去的
[/Quote]

转换规则是C/C++最复杂的条款之一。上面贴出来的只是数值转换部分,还有很多其它种类的转换。
飞天御剑流 2011-08-27
  • 打赏
  • 举报
回复
C99:

If an int can represent all values of the original type, the value is converted to an int;
otherwise, it is converted to an unsigned int. These are called the integer
promotions.48) All other types are unchanged by the integer promotions.
The integer promotions preserve value including sign. As discussed earlier, whether a ‘‘plain’’ char is treated as signed is implementation-defined.

6.3.1.2 Boolean type
1 When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.

6.3.1.3 Signed and unsigned integers
1 When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.
2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.49)
3 Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.

6.3.1.4 Real floating and integer
1 When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined.50)
2 When a value of integer type is converted to a real floating type, if the value being converted can be represented exactly in the new type, it is unchanged. If the value being converted is in the range of values that can be represented but cannot be represented exactly, the result is either the nearest higher or nearest lower representable value, chosen in an implementation-defined manner. If the value being converted is outside the range of values that can be represented, the behavior is undefined.

6.3.1.5 Real floating types
1 When a float is promoted to double or long double, or a double is promoted
to long double, its value is unchanged.
2 When a double is demoted to float, a long double is demoted to double or
float, or a value being represented in greater precision and range than required by its semantic type (see 6.3.1.8) is explicitly converted to its semantic type, if the value being converted can be represented exactly in the new type, it is unchanged. If the value being converted is in the range of values that can be represented but cannot be represented exactly, the result is either the nearest higher or nearest lower representable value, chosen in an implementation-defined manner. If the value being converted is outside the range of values that can be represented, the behavior is undefined.

6.3.1.6 Complex types
1 When a value of complex type is converted to another complex type, both the real and imaginary parts follow the conversion rules for the corresponding real types.

6.3.1.7 Real and complex
1 When a value of real type is converted to a complex type, the real part of the complex result value is determined by the rules of conversion to the corresponding real type and the imaginary part of the complex result value is a positive zero or an unsigned zero.
2 When a value of complex type is converted to a real type, the imaginary part of the
complex value is discarded and the value of the real part is converted according to the conversion rules for the corresponding real type.

6.3.1.8 Usual arithmetic conversions
1 Many operators that expect operands of arithmetic type cause conversions and yield result types in a similar way. The purpose is to determine a common real type for the operands and result. For the specified operands, each operand is converted, without change of type domain, to a type whose corresponding real type is the common real type. Unless explicitly stated otherwise, the common real type is also the corresponding real type of the result, whose type domain is the type domain of the operands if they are the same, and complex otherwise. This pattern is called the usual arithmetic conversions:

First, if the corresponding real type of either operand is long double, the other
operand is converted, without change of type domain, to a type whose corresponding real type is long double.
Otherwise, if the corresponding real type of either operand is double, the other
operand is converted, without change of type domain, to a type whose
corresponding real type is double.
Otherwise, if the corresponding real type of either operand is float, the other
operand is converted, without change of type domain, to a type whose corresponding real type is float.51)
Otherwise, the integer promotions are performed on both operands. Then the
following rules are applied to the promoted operands:
If both operands have the same type, then no further conversion is needed.
Otherwise, if both operands have signed integer types or both have unsigned
integer types, the operand with the type of lesser integer conversion rank is
converted to the type of the operand with greater rank.
Otherwise, if the operand that has unsigned integer type has rank greater or
equal to the rank of the type of the other operand, then the operand with
signed integer type is converted to the type of the operand with unsigned
integer type.
Otherwise, if the type of the operand with signed integer type can represent
all of the values of the type of the operand with unsigned integer type, then
the operand with unsigned integer type is converted to the type of the
operand with signed integer type.
Otherwise, both operands are converted to the unsigned integer type
corresponding to the type of the operand with signed integer type.
2 The values of floating operands and of the results of floating expressions may be
represented in greater precision and range than that required by the type; the types are not changed thereby.52)
jackyjkchen 2011-08-27
  • 打赏
  • 举报
回复
没事别乱转,我平均3000行代码出现一次转换
pathuang68 2011-08-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 luciferisnotsatan 的回复:]

这个不复杂呀,代码写多了自然就知道了。
而且,一般写代码时,都竟然做到类型匹配。而不是在那转来转去的
[/Quote]

++
飞天御剑流 2011-08-27
  • 打赏
  • 举报
回复
[Quote=引用楼主 cmarquis 的回复:]
signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long之间的类型转换,是否遵循以下原则?(size指sizeof(?))
1. size大小相同时(符号不同), 内部存储值不变;
2. 大size转化成小size时,内部存储值截取……
[/Quote]
咳,你搞这些代码是白费劲,编译器是给不了你答案的,请看标准的规定:

C89:

6.2.1 Arithmetic operands
6.2.1.1 Characters and integers

A char, a short int. or an int bit-field. or their signed or unsigned varieties. or an enumeration type. may be used in an expression wherever an int or unsigned int may be used If an int can represent all values of the original type. the value is converted to an inf;
otherwise, it is converted to an unsigned int. These are called the integral p~wnotions.” All other arithmetic types are unchanged by the integral promotions.
The integral promotions preserve value including sign. As discussed earlier, whether a “plain” char is treated as signed is implementation-defined.

6.2.1.2 Signed and unsigned integers

When a value with integral type is converted to another integral type, if the value can be represented by the new type, its value is unchanged.
When a signed integer is converted to an unsigned integer with equal or greater size, if the value of the signed integer is nonnegative. its value is unchanged. Otherwise: if the unsigned integer has greater size, the signed integer is first promoted to the signed integer corresponding to the unsigned integer: the value is converted to unsigned by adding to it one greater than the largest number that can be represented in the unsigned integer type ”
When a value with integral type is demoted to an unsigned integer with smaller size, the result is the nonnegative remainder on division by the number one greater than the largest unsigned number that can be represented in the type with smaller size. When a value with integral type is demoted to a signed integer with smaller size. or an unsigned integer is converted to its corresponding signed integer. if the value cannot be represented the result is implementation-defined

6.2.1.3 Floating and integral
When a value of floating type is convened 10 integral type. the fractional part is discarded It the value of the integral pan cannot be represented by the integral type. the behavior iz undetined.”
When a value of integral type is converted to Boating type. if the value being converted is in the range of values that can be represented but cannot be represented exactI>. the result i\ either the nearest hipher or nearest lower value. chosen in an implementation-defined manner

6.2.1.4 Floating types
When a float ih prbmoted to double or long double. or a double is promoted fo
long double. its value is unchanged. When a double is demoted to float or a long double to double or float. if the value being convened is outside the range of values that can be represented. the behavior is undefined. If the value being converted is in the range of values that can be represented but cannot be represented exactly. the result is either the nearest higher or nearest lower value.
chosen in an implementation-delined manner.

6.2.1.5 Usual arithmetic conversions
Many binary operators that expect operands of arithmetic type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the rtsual arithmetic cm~ersions:

First. if either operand has type long double, the other operand is converted to long double.
Otherwise, if either operand has type double, the other operand is converted to double.
Otherwise. if either operand has type float, the other operand is converted to float.
Otherwise. the integral promotions are performed on both operands. Then the following rules are applied:
If either operand has type unsigned long int, the other operand is converted to
unsigned long int.
Otherwise. if one operand has rype long int and the other has type unsigned
int. if a long int can represent all values of an unsigned int. the operand of
type unsigned int ih converted to long int; if a long int cannot represent
all the values of an unsigned int, both operands are converted to unsigned
long int
Othcrwtke. if either operand ha\ type long int, the other operand is converted to
long int
Otheruiw. if either operand has type unsigned int. the orher operand i\
converted 10 unsigned int
Othetwiw. horh opcrand~ have type int.
The value of Hoaring operands and of the results of floating expressions may be represented in greater precikn and range than that required by the type; the types are not changed thereby I”
加载更多回复(1)
1. C 语言中的指针和内存泄漏 5 2. C语言难点分析整理 10 3. C语言难点 18 4. C/C++实现冒泡排序算法 32 5. C++中指针和引用的区别 35 6. const char*, char const*, char*const的区别 36 7. C中可变参数函数实现 38 8. C程序内存中组成部分 41 9. C编程拾粹 42 10. C语言中实现数组的动态增长 44 11. C语言中的位运算 46 12. 浮点数的存储格式: 50 13. 位域 58 14. C语言函数二维数组传递方法 64 15. C语言复杂表达式的执行步骤 66 16. C语言字符串函数大全 68 17. C语言宏定义技巧 89 18. C语言实现动态数组 100 19. C语言笔试-运算符和表达式 104 20. C语言编程准则之稳定篇 107 21. C语言编程常见问题分析 108 22. C语言编程易犯毛病集合 112 23. C语言缺陷与陷阱(笔记) 119 24. C语言防止缓冲区溢出方法 126 25. C语言高效编程秘籍 128 26. C运算符优先级口诀 133 27. do/while(0)的妙用 134 28. exit()和return()的区别 140 29. exit子程序终止函数与return的差别 141 30. extern与static存储空间矛盾 145 31. PC-Lint与C\C++代码质量 147 32. spirntf函数使用大全 158 33. 二叉树的数据结构 167 34. 位运算应用口诀和实例 170 35. 内存对齐与ANSI C中struct内存布局 173 36. 冒泡和选择排序实现 180 37. 函数指针数组与返回数组指针的函数 186 38. 右左法则- 复杂指针解析 189 39. 回车和换行的区别 192 40. 堆和堆栈的区别 194 41. 堆和堆栈的区别 198 42. 如何写出专业的C头文件 202 43. 打造最快的Hash表 207 44. 指针与数组学习笔记 222 45. 数组不是指针 224 46. 标准C中字符串分割的方法 228 47. 汉诺塔源码 231 48. 洗牌算法 234 49. 深入理解C语言指针的奥秘 236 50. 游戏外挂的编写原理 254 51. 程序实例分析-为什么会陷入死循环 258 52. 空指针究竟指向了内存的哪个地方 260 53. 算术表达式的计算 265 54. 结构体对齐的具体含义 269 55. 连连看AI算法 274 56. 连连看寻路算法的思路 283 57. 重新认识:指向函数的指针 288 58. 链表的源码 291 59. 高质量的子程序 295 60. 高级C语言程序员测试必过的十六道最佳题目+答案详解 297 61. C语言常见错误 320 62. 超强的指针学习笔记 325 63. 程序员之路──关于代码风格 343 64. 指针、结构体、联合体的安全规范 346 65. C指针讲解 352 66. 关于指向指针的指针 368 67. C/C++ 误区一:void main() 373 68. C/C++ 误区二:fflush(stdin) 376 69. C/C++ 误区三:强制转换 malloc() 的返回值 380 70. C/C++ 误区四:char c = getchar(); 381 71. C/C++ 误区五:检查 new 的返回值 383 72. C 是 C++ 的子集吗? 384 73. C和C++的区别是什么? 387 74. 无条件循环 388 75. 产生随机数的方法 389 76. 顺序表及其操作 390 77. 单链表的实现及其操作 391 78. 双向链表 395 79. 程序员数据结构笔记 399 80. Hashtable和HashMap的区别 408 81. hash 表学习笔记 410 82. C程序设计常用算法源代码 412 83. C语言有头结点链表的经典实现 419 84. C语言惠通面试题 428 85. C语言常用宏定义 450
The C programming Language 第二版英文版 內容列表 Table of Contents Preface.......................................................... Preface to the first edition..................................... Introduction..................................................... Chapter 1 - A Tutorial Introduction.............................. 1.1 Getting Started................................ 1.2 Variables and Arithmetic Expressions........... 1.3 The for statement.............................. 1.4 Symbolic Constants............................. 1.5 Character Input and Output..................... 1.5.1 File Copying.......................... 1.5.2 Character Counting.................... 1.5.3 Line Counting......................... 1.5.4 Word Counting......................... 1.6 Arrays......................................... 1.7 Functions...................................... 1.8 Arguments - Call by Value...................... 1.9 Character Arrays............................... 1.10 External Variables and Scope.................. Chapter 2 - Types, Operators and Expressions..................... 2.1 Variable Names................................. 2.2 Data Types and Sizes........................... 2.3 Constants...................................... 2.4 Declarations................................... 2.5 Arithmetic Operators........................... 2.6 Relational and Logical Operators............... 2.7 Type Conversions............................... 2.8 Increment and Decrement Operators.............. 2.9 Bitwise Operators.............................. 2.10 Assignment Operators and Expressions.......... 2.11 Conditional Expressions....................... 2.12 Precedence and Order of Evaluation............ Chapter 3 - Control Flow......................................... 3.1 Statements and Blocks.......................... 3.2 If-Else........................................ 3.3 Else-If........................................ 3.4 Switch......................................... 3.5 Loops - While and For.......................... 3.6 Loops - Do-While............................... 3.7 Break and Continue............................. 3.8 Goto and labels................................ Chapter 4 - Functions and Program Structure...................... 4.1 Basics of Functions............................ 4.2 Functions Returning Non-integers............... 4.3 External Variables............................. 4.4 Scope Rules.................................... 4.5 Header Files................................... 4.6 Static Variables................................ 4.7 Register Variables.............................. 4.8 Block Structure................................. 4.9 Initialization.................................. 4.10 Recursion...................................... 4.11 The C Preprocessor............................. 4.11.1 File Inclusion........................ 4.11.2 Macro Substitution.................... 4.11.3 Conditional Inclusion................. Chapter 5 - Pointers and Arrays.................................. 5.1 Pointers and Addresses......................... 5.2 Pointers and Function Arguments................ 5.3 Pointers and Arrays............................ 5.4 Address Arithmetic............................. 5.5 Character Pointers and Functions............... 5.6 Pointer Arrays; Pointers to Pointers........... 5.7 Multi-dimensional Arrays....................... 5.8 Initialization of Pointer Arrays............... 5.9 Pointers vs. Multi-dimensional Arrays.......... 5.10 Command-line Arguments........................ 5.11 Pointers to Functions......................... 5.12 Complicated Declarations...................... Chapter 6 - Structures........................................... 6.1 Basics of Structures........................... 6.2 Structures and Functions....................... 6.3 Arrays of Structures........................... 6.4 Pointers to Structures......................... 6.5 Self-referential Structures.................... 6.6 Table Lookup................................... 6.7 Typedef........................................ 6.8 Unions......................................... 6.9 Bit-fields..................................... Chapter 7 - Input and Output..................................... 7.1 Standard Input and Output....................... 7.2 Formatted Output - printf....................... 7.3 Variable-length Argument Lists.................. 7.4 Formatted Input - Scanf......................... 7.5 File Access..................................... 7.6 Error Handling - Stderr and Exit................ 7.7 Line Input and Output........................... 7.8 Miscellaneous Functions......................... 7.8.1 String Operations...................... 7.8.2 Character Class Testing and Conversion. 7.8.3 Ungetc................................. 7.8.4 Command Execution...................... 7.8.5 Storage Management..................... 7.8.6 Mathematical Functions................. 7.8.7 Random Number generation............... Chapter 8 - The UNIX System Interface............................ 8.1 File Descriptors............................... 8.2 Low Level I/O - Read and Write................. 8.3 Open, Creat, Close, Unlink..................... 8.4 Random Access - Lseek.......................... 8.5 Example - An implementation of Fopen and Getc.. 8.6 Example - Listing Directories.................. 8.7 Example - A Storage Allocator.................. Appendix A - Reference Manual.................................... A.1 Introduction................................... A.2 Lexical Conventions............................ A.2.1 Tokens................................ A.2.2 Comments.............................. A.2.3 Identifiers........................... A.2.4 Keywords.............................. A.2.5 Constants............................. A.2.6 String Literals....................... A.3 Syntax Notation................................ A.4 Meaning of Identifiers......................... A.4.1 Storage Class......................... A.4.2 Basic Types........................... A.4.3 Derived types......................... A.4.4 Type Qualifiers....................... A.5 Objects and Lvalues............................ A.6 Conversions.................................... A.6.1 Integral Promotion.................... A.6.2 Integral Conversions.................. A.6.3 Integer and Floating.................. A.6.4 Floating Types........................ A.6.5 Arithmetic Conversions................ A.6.6 Pointers and Integers................. A.6.7 Void.................................. A.6.8 Pointers to Void...................... A.7 Expressions.................................... A.7.1 Pointer Conversion.................... A.7.2 Primary Expressions................... A.7.3 Postfix Expressions................... A.7.4 Unary Operators....................... A.7.5 Casts................................. A.7.6 Multiplicative Operators.............. A.7.7 Additive Operators.................... A.7.8 Shift Operators....................... A.7.9 Relational Operators.................. A.7.10 Equality Operators................... A.7.11 Bitwise AND Operator................. A.7.12 Bitwise Exclusive OR Operator........ A.7.13 Bitwise Inclusive OR Operator........ A.7.14 Logical AND Operator................. A.7.15 Logical OR Operator.................. A.7.16 Conditional Operator................. A.7.17 Assignment Expressions............... A.7.18 Comma Operator.......................... A.7.19 Constant Expressions.................... A.8 Declarations..................................... A.8.1 Storage Class Specifiers................. A.8.2 Type Specifiers.......................... A.8.3 Structure and Union Declarations......... A.8.4 Enumerations............................. A.8.5 Declarators.............................. A.8.6 Meaning of Declarators................... A.8.7 Initialization........................... A.8.8 Type names............................... A.8.9 Typedef.................................. A.8.10 Type Equivalence........................ A.9 Statements....................................... A.9.1 Labeled Statements....................... A.9.2 Expression Statement..................... A.9.3 Compound Statement....................... A.9.4 Selection Statements..................... A.9.5 Iteration Statements..................... A.9.6 Jump statements.......................... A.10 External Declarations........................... A.10.1 Function Definitions.................... A.10.2 External Declarations................... A.11 Scope and Linkage............................... A.11.1 Lexical Scope........................... A.11.2 Linkage................................. A.12 Preprocessing................................... A.12.1 Trigraph Sequences...................... A.12.2 Line Splicing........................... A.12.3 Macro Definition and Expansion.......... A.12.4 File Inclusion.......................... A.12.5 Conditional Compilation................. A.12.6 Line Control............................ A.12.7 Error Generation........................ A.12.8 Pragmas................................. A.12.9 Null directive.......................... A.12.10 Predefined names....................... A.13 Grammar......................................... Appendix B - Standard Library.................................... B.1.1 File Operations................................ B.1.2 Formatted Output......................... B.1.3 Formatted Input.......................... B.1.4 Character Input and Output Functions..... B.1.5 Direct Input and Output Functions........ B.1.6 File Positioning Functions............... B.1.7 Error Functions.......................... B.2 Character Class Tests: ................. B.3 String Functions: ..................... B.4 Mathematical Functions: ................. B.5 Utility Functions: ....................

70,024

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧