Homepage › Forums › Articles › Programming › C, C++, and C# › Type Qualifiers in C
Tagged: c-language, cplusplus, datatype, development, objective-c, programming, register, storage, variable
This topic was published by DevynCJohnson and viewed 4062 times since "". The last page revision was "".
Viewing 1 post (of 1 total)
- AuthorPosts
Many programmers may be confused about the different type-qualifiers and their meanings. Here is a brief description of some type qualifiers in C (and similar languages).
Clockwise/Spiral Rule - Read the type qualifiers backwards
int*
- pointer to intint const*
- pointer to const int (const int*
==int const*
)int *const
- const pointer to intint const *const
- const pointer to const int (const int* const
==int const *const
)int **
- pointer to pointer to intint **const
- const pointer to pointer to intint *const *
- pointer to const pointer to intint const **
- pointer to pointer to const intint *const *const
- const pointer to const pointer to intvolatile int *const
- constant pointer to volatile intvoid (*signal(int, void (*fp)(int)))(int)
- signal is a function passing an int and a pointer to a function passing an int returning nothing (void) returning a pointer to a function passing an int returning nothing (void)
Storage classes (listed below) come before type-qualifiers (also listed below). Only one storage class can be used when declaring a variable.
Storage Classes
- auto - Stored in stack during the code-block
- extern - Lasts the whole program, block, or compilation unit; globally visible
- register - Stored in stack or CPU-register during the code block
- static - Lasts the whole program, block, or compilation unit; private in program
- typedef - The data specifies a new datatype
- __thread - Thread-local-storage; one instance per thread
- _Thread_local - Thread-local data
Type-Qualifiers
- const - Value does not change; read-only
- restrict - For the lifetime of the pointer, the object can only be accessed via the pointer
- volatile - Optimizing-compilers must not change
- _Atomic - Map a variable to one of the 5 basic built-in types
Further Reading
- Programming and Development (Article Index) - https://dcjtech.info/topic/programming-and-development/
- C Programming Article Forum - https://dcjtech.info/forum/articles/programming/c-c-and-c/
- Writing Your First C Program in Linux - https://dcjtech.info/topic/writing-your-first-c-program-in-linux/
- Compiler Warnings are Helpful; Do Not Ignore - https://dcjtech.info/topic/compiler-warnings-are-helpful-do-not-ignore/
- C vs C++ vs Objective-C vs etc - https://dcjtech.info/topic/c-vs-c-vs-objective-c-vs-etc/
- Machine Modes Used in C Attributes - https://dcjtech.info/topic/machine-modes-used-in-c-attributes/
- Standard C Libraries - https://dcjtech.info/topic/standard-c-libraries/
- Standard C Library Headers - https://dcjtech.info/topic/standard-c-library-headers/
- Linux Compilers - https://dcjtech.info/topic/linux-compilers/
- GNU-Toolchain - https://dcjtech.info/topic/gnu-toolchain/
- C Code Examples: Array Rotations - https://dcjtech.info/topic/c-code-examples-array-rotations/
- C Code Examples: Cyclic Redundancy Check (CRC) - https://dcjtech.info/topic/c-code-examples-cyclic-redundancy-check-crc/
- C Code Examples: File IO Tests - https://dcjtech.info/topic/c-code-examples-file-io-tests/
- C Code Examples: Stack and Queue Datatype - https://dcjtech.info/topic/c-code-examples-stack-and-queue-datatype/
- AuthorPosts
Viewing 1 post (of 1 total)