What's new in C99
Introducing the new features of C99.
One-line comment by "//"
The C language comment was only "/ * comment * /", but the one-line comment by "//" was officially adopted in C99. rice field.
// comment
Local variable declaration is possible at any position
From C99, you can declare local variables at any position. The restriction that the declaration of a local variable must be at the beginning of the block is removed.
#include <stdint.h> int main (void) { { int32_t num1 = 5; 1 + 1; // Local variables can be declared at any position int32_t num2 = 4; } }
Local variables can be declared in the loop variable initialization part of the for statement
Local variable declaration is now possible in the loop variable initialization part of for statement became.
#include <stdint.h> #include <stdio.h> int main (void) { int32_t total = 0; // Declare variables in the loop variable initialization part of for for (int32_t i = 0; i <10; i ++) { total + = i; } printf("%d\n", total); }
Integer type that can specify a certain width
Integer types are now available that allow you to specify a certain width.
- int8_t --Signed 8-bit integer type
- int16_t --Signed 16bit integer type
- int32_t --Signed 32-bit integer type
- int64_t --Signed 64-bit integer type
- uint8_t --Unsigned 8bit integer type
- uint16_t --Unsigned 16bit integer type
- uint32_t --Unsigned 32bit integer type
- uint64_t --Unsigned 64-bit integer type
Integer type that can be converted to and from a pointer
Specify the member variable name of the structure and specify the value
You can now specify a value by specifying the member variable name of structure.
#include <stdint.h> #include <stdio.h> // Definition of a structure that represents book information struct myapp_book { int32_t id; const char * name; int32_t price; };; int main (void) { // Declare and initialize structure variables (specify member variable names and specify values) struct myapp_book book = {.id = 1, .name = "C99 Book", .price = 2000}; printf("id:%d, name:%s, price:%d\n", book.id, book.name, book.price); }