C99 Standard update

Source: Internet
Author: User

1. Add a restrict pointer.
C99 adds a restrict type modifier for the pointer, which is the only way to access the object indicated by the pointer initially. Therefore, only
You can use the restrict pointer expression to access objects. The restrict pointer is mainly used as a function variable, or points to the memory variable allocated by the malloc () function.
The restrict data type does not change the semantics of the program.
If a function defines two restrict pointers, the compiler assumes that they point to two different objects. The memcpy () function is a typical example of a restrict pointer. The memcpy () function prototype in c89 is as follows:

Code:

--------------------------------------------------------------------------------
Void * memcpy (void * S1, const void * S2, size_t size );
--------------------------------------------------------------------------------

If S1 and S2 point to an object that overlaps, the operation is undefined. The memcpy () function can only be used for non-overlapping objects. The prototype of the memcpy () function in c99 is as follows:

Code:

--------------------------------------------------------------------------------
  
Void * memcpy (void * restrict S1, const void * restrict S2, size_t size );
--------------------------------------------------------------------------------

By modifying S1 and S2 variables using restrict, you can ensure that they point to different objects in the prototype.

2. inline (Inline) KEYWORDS
In addition to maintaining a structured and functional definition method, inline functions allow programmers to write highly efficient code.
Returning will consume a considerable amount of system resources, especially when function calls occur in loop statements with many repetitions. in general, when the swap function is called, the variable needs to be written into the stack, and the memory of various registers needs
Save. When the function returns, the register content needs to be restored. If the function is online extended in the Code, when the code is executed, these save and restore operations will happen again, and the function call speed will be faster.
Degree will be greatly accelerated. Online expansion of functions produces long code. Therefore, you should only inline functions that have a significant impact on the application program and short functions.
 
3. New Data Types
_ Bool
The value is 0 or 1. The header folder <stdbool. h> is added to c99 to define bool, true, and false macros, so that programmers can write applications compatible with C and C ++ at the same time. When writing new applications, you should use
<Stdbool. h> the bool macro in the header file.

_ Complex and _ imaginary
The plural types defined in the c99 standard are as follows: float_complex; float_imaginary; double_complex; double_imaginary; long double_complex; long double_imaginary.
<Complex. h> the header file defines complex and imaginary macros and extends them to _ complex and _ imaginary. Therefore, you should use <stdbool when writing new applications. h> the complex and imaginary Macros in the header file.

Long long int
The c99 standard introduces long int (-(2e63-1) to 2e63-1) and unsigned long int (0-2e64-1 ). Long long int supports 64-bit integer length.

4. array Enhancement
Variable Length Array
In c99, when a programmer declares an array, the dimension of the array can be determined by any valid integer expression, including an expression that determines its value only at runtime. Such an array is called a variable length array, however, only partial Arrays can become longer.
The dimensions of the Variable Length array remain unchanged during the lifetime of the array. That is to say, the variable length array is not dynamic. only the size of the array can be changed. you can use * to define a variable length array with uncertain length.
  
Type modifier in array declaration
 
In c99, if you need to use an array as the function variable, you can use the static keyword in the square brackets declared by the array. This is equivalent to telling the Compilation Program that the variable points to an array that contains at least the specified
Number of elements. You can also use the restrict, volatile, and const keywords in square brackets declared by the array, but only for function variable. If you use restrict, pointer
Is the only way to initially access this object. If you use const, the pointer always points to the same array. Using volatile makes no sense.

5. Single line comment
The single line comment mark "//" is introduced, which can be used like C ++.

6. Scattered code and Declaration

7. Modify the Preprocessing Program
A. Variable list
Macros can contain variable elements, which are expressed by ellipsis (...) in macro definition. The internal preprocessing identifier _ va_args _ determines where the variable will be replaced. Example: # define mysum (...) sum (_ va_args _) Statement mysum (K, M, N );
Set
Converted to sum (K, m, n). The variable can also contain the variable. Example: # define compare (compf ,...)
Compf (_ va_args _) compare (strcmp, "small", "large ");
Replace it with strcmp ("small", "large ");
B. _ Pragma Operator
C99 introduces another method for defining compilation commands in a program: _ Pragma operator. The format is as follows:
_ Pragma ("directive ")
In this example, direve VE is the compilation command to be full. The _ Pragma operator allows compilation commands to be used in macro replacement.
C. Internal compilation commands
If stdcfp_contract On/Off/default is on, the floating point expression is treated as an independent unit based on hardware. The default value is a defined tool.
Stdcfevn_access On/Off/default indicates that the compiler can access the floating point environment. The default value is a defined tool.
Stdc cx_limited_range On/Off/default if the value is on, it is equivalent to telling the compile program that some formulas containing plural numbers are reliable. The default value is off.
D. New Internal macros
_ Stdc_hosted _ If the operating system exists, it is 1
_ Stdc_version _ 5o91l or higher. Represents the C version
_ Stdc_iec_599 _ If the IEC 60559 floating point operation is supported, the value is 1.
_ Stdc_iec_599_complex _ If the IEC 60599 complex operation is supported, the value is 1.
_ Stdc_iso_000046 _ supported by the compiler, used to describe the ISO/IEC 10646 Standard year and month format: yyymmml

8. Variable declaration in the for statement
In c99, programmers can define one or more variables in the initialization Part Of The for statement. The scope of these variables is only in the loop body controlled by this for statement. For example:

Code:

--------------------------------------------------------------------------------
For (INT I = 0; I <10; I ++ ){
// Do someting...
}
--------------------------------------------------------------------------------

9. compound assignment
In c99, you can specify an array, structure, or union expression of the object type in composite assignment. When a compound value is used, the type should be specified in the arc, followed by the initialization list enclosed by curly brackets. If the type is array, the array size cannot be specified. The built object is not named.
Example: Double * fp = (double []) {1.1, 2.2, 3.3 };
This statement is used to create a pointer FP pointing to double, and the Pointer Points to the first element of the three element array. Composite assignments created in the file domain are valid only for the entire lifetime of the program. The composite assignment created in the module is a local object and does not exist after exiting the module.

10. Flexible array structure member
In c99, the last element in the structure can be an array of unknown sizes. This is called a flexible array member, but before the flexible array member in the Structure
At least one other member is required. Flexible array Members allow the structure to contain an array of variable sizes. The size of the structure returned by sizeof does not include the memory of the flexible array. Structure containing flexible array members
The malloc () function dynamically allocates memory, and the allocated memory should be larger than the structure size to adapt to the expected size of the flexible array.

11. Specified initialization character
In c99, this feature is very useful for programmers who frequently use sparse arrays. The specified initialization character can be used as an array, as well as a structure and a union. Array format: [Index] = vol. index indicates the subscript of the array, and vol indicates the initialization value of the array element.
For example, int X [10] = {[0] = 10, [5] = 30}. Only X [0] and X [5] are initialized. the format used for structure or union is as follows:
Member-Name (member name)
You can use a simple method to initialize a specified member of a structure when initializing the structure.
Example: struct example {int K, M, N;} object = {M = 10, n = 200 };
K is not initialized. There is no limit on the order in which the structure members are initialized.

12. Enhancements to the printf () and scanf () function series
In c99, printf () and scanf () functions are introduced to process long
Features of long int and unsigned long int data types. Long long int
The Type format modifier is ll. In printf () and scanf () functions, ll applies to D, I, O, u
And x format. In addition, the HH modifier is introduced in c99. When using D, I, O,
HH is used to specify the char variable when the U and X format specifiers are used. Both the ll and HH modifiers can be used as the N specifiers.
When the format modifiers A and A are used in the printf () function
The result outputs a hexadecimal floating point number. Format: [-] 0xh, hhhhp + d
When the format modifier is used, X and P must be uppercase. The format modifiers A and A can also be used in the scanf () function to read floating point numbers. When calling the printf () function, the description in % F is allowed.
Add the L modifier (% lf) before the modifier, but it does not work.

13. database Added by c99
  
Standard header file in c89
<Assert. h> define macro assert ()
<Ctype. h> Character Processing
<Errno. h> Error Report
<Float. h> define implementation-related floating-point duty
<Limits. h> defines implementation-related limits.
<Locale. h> the setlocale () function is supported ()
<Math. h> definitions used by the mathematical function library
<Setjmp. h> supports non-local jump
<Signal. h> define the signal value
<Stdarg. h> variable-length list
<Stddef. h> define common Constants
<Stdio. h> supports file input and output.
<Stdlib. h> other declarations
<String. h> support for string functions
<Time. h> support for system time functions

Header files and libraries added by c99
<Complex. h> supports the plural algorithm.
<Fenv. h> provides access to the floating-point status mark and other aspects of the floating-point environment.
<Inttypes. h> defines a set of standard and portable integer types. It also supports functions that process Integers of the maximum width.
<Iso646.h> first introduced in the first revision in 1995 to define macros corresponding to various operators
<Stdbool. h> supports the boolean data type. Define macro bool to be compatible with C ++
<Stdint. h> defines a set of standard and portable integer types. This file is included in <inttypes. h>
<Tgmath. h> define general floating point macros
<Wchar. h> first introduced in the first revision in 1995 to support multibyte and wide byte Functions
<Wctype. h> it was introduced in the first revision in 1995 to support multibyte and wide byte classification functions.

14. _ FUNC _ predefined identifier
Specifies the name of the function stored in _ FUNC _, which is similar to the value assignment of a string.

15. Changes to other features

Relaxed conversion restrictions
 
C89 standard c99 Standard
Data Block nesting layer 15 127
Number of nested layers of conditional statements 8 63
Number of valid characters in the internal identifier 31 63
The number of valid characters in the external identifier is 6 31.
127 Members in a structure or union
Number of parameters in function call 31 127

Implicit int rules are no longer supported

Removed the implicit function declaration.

Constraints on return values
In c99, non-null functions must use return statements with return values.

Extended Integer type
Extended type description
Int16_t integer length is precise 16 bits
Int_least16_t integer length is at least 16 bits
Int_fast32_t is the most stable Integer type, with a length of at least 32 characters
Intmax_t maximum integer type
Uintmax_t maximum unsigned integer type

Improvement on Integer type escalation rules
In c89, the expression type is Char, and the value of short Int or Int can be upgraded to int or unsigned Int.
In c99, each integer type has a level. for example, the level of long int is higher than that of int, and the level of int is higher than that of char. in an expression, any integer type lower than Int or unsigned int can be replaced with Int or unsigned Int.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.