2023#
C Double Pointer(Pointer-to-Pointer)
Since pointers are variables themselves, they can be stored in arrays just as other variables can.
The pointer to a pointer in C is used when we want to store the address of another pointer.
C Pointers to Functions
There is yet another construct for which the address-of operator &
can be used: functions.
A function pointer, also called a subroutine pointer or procedure pointer, is a pointer referencing executable code, rather than data. Dereferencing the function pointer yields the referenced function, which can be invoked and passed arguments just as in a normal function call. Such an invocation is also known as an "indirect" call, because the function is being invoked indirectly through a variable instead of directly through a fixed identifier or address.
Function pointers allow different code to be executed at runtime. They can also be passed to a function to enable callbacks.
The advantage of using function pointers is that multiple modules implementing the same function can be identified together, making maintenance easier and the system structure clearer. Or to summarise: it is easy to design layers, promotes system abstraction, reduces coupling and separates the interface from the implementation.
C Pointer Validity
Previously, we've discussed const qualifier and Named Constants in C. Today let's go back to the root and have a look at null pointers and pointer validity. After all, everything starts at zero and disappears without a trace.
C Named Constants
const
-qualified read-only variables must be initialized and named at the same time as they are defined.
Pointers are opaque objects that can remain in a valid, null or indeterminate state. Always initialise pointers to 0 as soon as possible.
const qualifier in C
const
is the abbreviation for "constant". Unfortunately, because of this, many people think that the value qualified by const
is a constant. This is not correct. More accurately, it should be a read-only variable whose value cannot be used at compile time because the compiler does not know its stored content at compile time. Perhaps this keyword should have been replaced by readonly. So what is the use and meaning of this keyword?
The original purpose of const
was to replace precompiled instructions, eliminating their shortcomings and inheriting their advantages. Let's see the difference between it and the #define
macro.
In C, the const
keyword should probably be replaced with readonly.
C Pointer as Function Argument
So far, we've discussed C Pointers and Arrays, C Character Pointer and String Manipulation and C Pointer and Array Cross Reference with Mismatched Type. To be frank, there are some very confusing names for some of these concepts, and it's very easy for even an old hand programmer to get them all mixed up.
In this article, we'll explore the syntax of passing parameters to functions using arrays or pointers. What does it actually do behind the scenes? Can it really pass an array or a pointer to a function? What is the connection and difference between these two ways of passing parameters?
ARM64 exclusive Load/Store
ARMv7-A and ARMv8-A architectures both provide support for exclusive memory accesses. In A64, this is the Load/Store exclusive (LDXR
/STXR
) pair.
In an SMP (Symmetric multiprocessing) system, data accesses must frequently be restricted to one modifier at any particular time.
ARM64 One-Way Barriers
In the previous article ARM64 Memory Barriers, we systematically sorted out and summarized common memory barrier instructions.
AArch64 adds new load and store instructions with implicit barrier semantics. These require that all loads and stores before or after the implicit barrier are observed in program order.