Final conclusion: arithmetic on a void* is illegal in both C and C++.

GCC allows it as an extension, see Arithmetic on void- and Function-Pointers (note that this section is part of the "C Extensions" chapter of the manual). Clang and ICC likely allow void* arithmetic for the purposes of compatibility with GCC. Other compilers (such as MSVC) disallow arithmetic on void*, and GCC disallows it if the -pedantic-errors flag is specified, or if the -Werror=pointer-arith flag is specified (this flag is useful if your code base must also compile with MSVC).

The C Standard Speaks

Quotes are taken from the n1256 draft.

The standard's description of the addition operation states:

6.5.6-2: For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object type and the other shall have integer type.

So, the question here is whether void* is a pointer to an "object type", or equivalently, whether void is an "object type". The definition for "object type" is:

6.2.5.1: Types are partitioned into object types (types that fully describe objects) , function types (types that describe functions), and incomplete types (types that describe objects but lack information needed to determine their sizes).

And the standard defines void as:

6.2.5-19: The void type comprises an empty set of values; it is an incomplete type that cannot be completed.

Since void is an incomplete type, it is not an object type. Therefore it is not a valid operand to an addition operation.

Therefore you cannot perform pointer arithmetic on a void pointer.

Notes

Originally, it was thought that void* arithmetic was permitted, because of these sections of the C standard:

6.2.5-27: A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.

However,

The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and members of unions.

So this means that printf("%s", x) has the same meaning whether x has type char* or void*, but it does not mean that you can do arithmetic on a void*.

Answer from Sadeq on Stack Overflow
Top answer
1 of 10
374

Final conclusion: arithmetic on a void* is illegal in both C and C++.

GCC allows it as an extension, see Arithmetic on void- and Function-Pointers (note that this section is part of the "C Extensions" chapter of the manual). Clang and ICC likely allow void* arithmetic for the purposes of compatibility with GCC. Other compilers (such as MSVC) disallow arithmetic on void*, and GCC disallows it if the -pedantic-errors flag is specified, or if the -Werror=pointer-arith flag is specified (this flag is useful if your code base must also compile with MSVC).

The C Standard Speaks

Quotes are taken from the n1256 draft.

The standard's description of the addition operation states:

6.5.6-2: For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object type and the other shall have integer type.

So, the question here is whether void* is a pointer to an "object type", or equivalently, whether void is an "object type". The definition for "object type" is:

6.2.5.1: Types are partitioned into object types (types that fully describe objects) , function types (types that describe functions), and incomplete types (types that describe objects but lack information needed to determine their sizes).

And the standard defines void as:

6.2.5-19: The void type comprises an empty set of values; it is an incomplete type that cannot be completed.

Since void is an incomplete type, it is not an object type. Therefore it is not a valid operand to an addition operation.

Therefore you cannot perform pointer arithmetic on a void pointer.

Notes

Originally, it was thought that void* arithmetic was permitted, because of these sections of the C standard:

6.2.5-27: A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.

However,

The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and members of unions.

So this means that printf("%s", x) has the same meaning whether x has type char* or void*, but it does not mean that you can do arithmetic on a void*.

2 of 10
73

Pointer arithmetic is not allowed on void* pointers.

🌐
GNU
gcc.gnu.org › onlinedocs › gcc › Pointer-Arith.html
Pointer Arith (Using the GNU Compiler Collection (GCC))
In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions.
🌐
Quora
quora.com › Why-is-pointer-arithmetic-with-“void*”-considered-bad-What-are-some-bad-scenarios-for-this-application
Why is pointer arithmetic with “void*” considered bad? What ...
Answer (1 of 3): The biggest reason you don't want to do void pointer math (if the compiler even lets you) is portability. Pointers reference elements of arrays. Those elements always have an intrinsic size. Type int, for example, could be 2, 4, 8, or more bytes depending on the target architect...
🌐
Quora
quora.com › Why-cant-I-perform-arithmetic-on-a-void-pointer
Why can't I perform arithmetic on a void pointer? - Quora
Answer (1 of 3): To be able to perform pointer arithmetic, the compiler must know the exact size (number of bytes) of the object the pointer points to. Otherwise, it has no idea how much to increment or decrement the address contained in the ...
🌐
GeeksforGeeks
geeksforgeeks.org › c language › void-pointer-c-cpp
void Pointer in C - GeeksforGeeks
The below C program demonstrates the usage of a void pointer to perform pointer arithmetic and access a specific memory location.
Published   July 17, 2014
🌐
Google Groups
groups.google.com › g › osv-dev › c › XOESSQvoXlY
[RFC] Arithmetic on void pointers
Hello, It seems like clang doesn't really care much for "-Wno-pointer-arith" for C++11 code: int main() { void *p = reinterpret_cast<void*>(0xdeadbeef); printf("%p\n", p + 8); } [penberg@localhost tmp]$ clang++ -std=gnu++11 -Wall -Wno-pointer-arith pointer-arith.cpp pointer-arith.cpp:7:22: error: arithmetic on a pointer to void printf("%p\n", p + 8); ~ ^ 1 error generated.
🌐
YouTube
youtube.com › watch
What about Pointer Arithmetic with Void Pointers? - YouTube
Patreon ➤ https://www.patreon.com/jacobsorberCourses ➤ https://jacobsorber.thinkific.comWebsite ➤ https://www.jacobsorber.com---What about Pointer Arithmetic...
Published   July 26, 2022
Find elsewhere
🌐
Google Groups
groups.google.com › g › comp.lang.c › c › RRsX0Z3MUjY
arithmetic on a void * pointer
If you want to advance a void* so it points n bytes later in memory, you can do this: buf = (char*)buf + n; (note that the char* result is implicitly converted back to void*). One advantage if this is that you can advance by n ints rather than n chars if you want to. Or, if you know you're going to be performing byte-oriented arithmetic on a pointer object, you can just declare it as a char* (or unsigned char*) in the first place.
🌐
Fresh2Refresh
fresh2refresh.com › home › c programming tutorial › c interview questions › is void pointer arithmetic a valid one? why?
Is void pointer arithmetic a valid one? Why? | Fresh2Refresh.com
July 5, 2018 - Arithmetic operation on void pointer is not valid one. Void pointer is a generic pointer. It is not referring int, char or any other data type specifically.
🌐
Texas Instruments E2E
e2e.ti.com › support › tools › code-composer-studio-group › ccs › f › code-composer-studio-forum › 927303 › compiler-msp-cgt-bug-arithmetic-on-pointer-to-void-produces-incorrect-code-in-comparisons-and-optimisations
Compiler/MSP-CGT: BUG: Arithmetic on pointer to void produces incorrect code in comparisons (and optimisations)
That said, many compilers, including the TI MSP430 compiler, handle it by pretending it points to char instead of void. ... Many warning diagnostics, including this one, can be changed to an error on the compiler command line. Add the compiler option --display_error_number, and the compiler shows the diagnostic number in the message. % cl430 --opt_level=4 -s -vmspx --display_error_number file.c "file.c", line 8: warning #1219-D: arithmetic on pointer to void or function type "file.c", line 11: warning #1219-D: arithmetic on pointer to void or function type "file.c", line 12: warning #1219-D: arithmetic on pointer to void or function type
🌐
Cplusplus
cplusplus.com › forum › unices › 60998
Void* arithmetic - C++ Forum
Hello everyone, For a school project I am working on, I must use an array of unspecified objects: void* voidarray; In addition to this pointer, I need another one that points to a specific location beyond that address: void* voidarray2 = voidarray + offset; // offset is an integer However, I just learned that void* arithmetic is not allowed in C.
🌐
OverIQ
overiq.com › c-programming-101 › void-pointers-in-c
Void Pointers in C - C Programming Tutorial - OverIQ.com
Here we have assigned the name of the array one_d to the void pointer vp. Since the base type of one_d is a pointer to int or (int*), the void pointer vp is acting like a pointer to int or (int*). So the proper typecast is (int*). The following program demonstrates pointer arithmetic in void pointers.
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Pointer-Arithmetic.html
Pointer Arithmetic (GNU C Language Manual)
Here is an example, in which adding a positive integer advances the pointer to a later element in the same array. void incrementing_pointers () { int array[5] = { 45, 29, 104, -3, 123456 }; int elt0, elt1, elt4; int *p = &array[0]; /* Now p points at element 0.
🌐
Unstop
unstop.com › home › blog › void pointer in c explained in detail with code examples
Void Pointer In C Explained In Detail With Code Examples // Unstop
March 1, 2024 - The void pointer is used to read and display the value of num, which results in an output of 23. ... C does not provide arithmetic operations on void pointers.
🌐
GitHub
github.com › nasa › SBN › issues › 16
code in sbn/fsw/src/sbn_pack.h uses void *pointer arithmetic · Issue #16 · nasa/SBN
January 2, 2020 - While GCC allows it: It is non standard: The C standard does not allow void pointer arithmetic. However, GNU C is allowed by considering the size of void is 1. C11 standard §6.2.5 Paragraph - 19 The void type comprises an empty set of va...
Published   Mar 16, 2020
🌐
upGrad
upgrad.com › home › tutorials › software & tech › void pointer
Mastering Void Pointers: A Comprehensive Tutorial
October 27, 2025 - Because of their adaptability, ... change over time. However, you cannot directly dereference or use pointer arithmetic on a void pointer since it lacks information about the type it points to....