What is a virtual table pointer in C? No vptr, do this
C has no vptr. Learn how to add a pointer to a shared function table yourself and dispatch through it, as C++ does behind the scenes.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
C has no vptr. Learn how to add a pointer to a shared function table yourself and dispatch through it, as C++ does behind the scenes.
A vtable is a C++ implementation detail that makes virtual calls work. C has none, but a struct of function pointers gives the same dispatch.
C has no friend function: it lacks classes and access control. Learn the C++ feature and the C alternatives, such as opaque pointers and internal headers.
C has no friend classes, but opaque pointers, static linkage and private headers give similar encapsulation. This guide shows the patterns with code.
C has no templates, so no template specialization. Here are the C11 and macro techniques that give you type-specific code, with working examples.
The C null statement is a single semicolon. See where it is useful, how a stray semicolon after if or for causes bugs, and how to catch it.
C gained the nullptr keyword and nullptr_t type in C23. Learn how they differ from NULL, when to use each and which compilers support them.
typeid is a C++ operator for runtime type information. C has no equivalent, so you use type tags or _Generic instead.
C has no decltype; that is C++. Use typeof, standard in C23, plus auto and _Generic for type-aware code.
In C a type alias is created with typedef and gives an existing type a second name. See structs, function pointers, pitfalls and how it differs from #define.
Bit fields let a C struct member use a set number of bits. See the syntax, restrictions, implementation-defined layout and safer alternatives.
A union in C shares one block of memory between its members. See declaration, size, tagged unions and type punning with runnable code.
A null pointer in C holds a value that points to nothing. Learn how to declare it, where it is used and how to avoid null dereference crashes.
A function pointer in C stores the address of a function so you can call it indirectly, pass it as a callback or select behaviour at runtime.
C has no destructors, so cleanup is manual. See the destroy-function, goto cleanup and cleanup-attribute patterns that replace them.
C has no private virtual functions. This explains the C++ feature, the Non-Virtual Interface idiom, and a C equivalent using opaque structs and function pointers.
A static variable in C lives for the whole program and is initialised once. Learn static local and file-scope variables, defaults and thread safety.
C has no inheritance, so the diamond problem does not exist in C itself. See what happens when you emulate it with structs and how C++ and other languages solve it.
C has no sealed classes, but opaque types and static functions give similar protection. See examples and the limits of the approach.
C has no abstract classes, but a struct of function pointers and first-member embedding give you the same design. See the pattern with a full example.