void-pointers Questions

4

Solved

I'm looking through an API written in C++ and I'm confused as to what the following parameter type means: void*& data Does that mean the user would pass in a reference to a void pointer? If tha...
Wingless asked 20/11, 2010 at 19:55

4

Solved

In which situation should we prefer a void pointer over a char pointer or vice-versa? As a matter of fact both can be type cast to any of the data types.
Anzus asked 26/12, 2018 at 12:29

2

Solved

I'm using a library which requires a function with a void* pointer as a parameter. I have a 2D string array and I want to pass that array through that parameter and extract it inside the function. ...
Adham asked 2/6, 2023 at 6:16

10

Solved

Why is it impossible to have a reference to void? The only thing I found in the C++ Standard is this line, at 8.3.2.1 A declarator that specifies the type "reference to cv void" is ill-formed. ...
Heall asked 19/1, 2009 at 15:9

3

Solved

This question is about the 'function pointer' version of qsort from K&R (2e), section 5.11 (p118-121). There are a number of places where I don't understand why or how the casts work, and I sus...

6

Solved

From the C17 draft (6.3.2.3 ¶3): An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.67) If a null pointer constant is con...
Fibrillation asked 10/5, 2023 at 14:14

3

Solved

I've been reading some articles about void* type pointers and found this requirement from the Standard. 6.2.5.27: A pointer to void shall have the same representation and alignment requirements as...
Bohn asked 10/1, 2021 at 9:17

10

When a pointer to a particular type (say int, char, float, ..) is incremented, its value is increased by the size of that data type. If a void pointer which points to data of size x is incremented,...
Coulee asked 19/8, 2010 at 15:5

10

Recently, I came across the following statement: It's quite common for all pointers to have the same size, but it's technically possible for pointer types to have different sizes. But then I came...
Pneumectomy asked 14/4, 2022 at 10:35

5

I am learning C++ using C++ Primer 5th edition. In particular, i read about void*. There it is written that: We cannot use a void* to operate on the object it addresses—we don’t know that object’s...
Transoceanic asked 14/4, 2022 at 8:58

4

Solved

Error 1 error C2036: 'const void *' : unknown size file.cpp 111 I don't follow. GCC never complains about void * pointer arithmetic, even on -ansi -pedantic -Wall. What's the problem? Here's th...
Buckman asked 17/8, 2010 at 2:14

4

Solved

I'm writing an interpreter and I'd like to be able to store whatever value a function returns into a void pointer. I've had no problem storing ints and various pointers as void pointers but I get a...
Volar asked 4/7, 2011 at 19:23

2

Solved

This question is similar to "Are all pointers guaranteed to round-trip through void * correctly?" but slightly deeper. Given: #include <stdint.h> int i; int *ip1 = &i; void *vp...
Profile asked 14/9, 2021 at 15:10

4

Solved

I'm using an API that accepts void* in certain functions. I frequently accidentally pass the wrong pointer type to the function, and of course it compiles fine, but doesn't work at runtime. Is ther...
Sarita asked 5/8, 2021 at 21:0

5

Solved

One of my friends pointed out from "Understanding and Using C Pointers - Richard Reese, O'Reilly publications" the second bullet point and I wasn't able to explain the first sentence from...
Franke asked 1/8, 2021 at 13:18

2

When implementing certain data structures in C++ one needs to be able to create an array that has uninitialized elements. Because of that, having buffer = new T[capacity]; is not suitable, as new ...

6

plain C have nice feature - void type pointers, which can be used as pointer to any data type. But, assume I have following struct: struct token { int type; void *value; }; where value field ...
Bekki asked 25/4, 2011 at 22:4

1

Solved

I am using std::unique_ptr in this way: template <typename Pointer, auto deleter> using my_unique_ptr = std::unique_ptr<std::remove_pointer<Pointer>, std::integral_constant<declty...
Crescint asked 4/3, 2021 at 16:19

16

Is it possible to dereference a void pointer without type-casting in the C programming language? Also, is there any way of generalizing a function which can receive a pointer and store it in a voi...
Orabelle asked 28/3, 2009 at 10:33

3

Solved

Summarizing the C standard, specifically ISO/IEC 9899:201x §6.3.2.3 - 3: If a pointer is being compared to the constant literal 0, then this is a check to see if the pointer is a null pointer. This...
Francium asked 19/10, 2020 at 9:50

3

Solved

I have a void pointer as a parameter for a function. It is currently pointing to an int. When I try to free it, it returns a bus error. Should I be freeing void pointers? If so, how do I do so?
Bradney asked 15/5, 2020 at 23:4

2

Solved

Is there a way to cast a Swift struct's address to a void UnsafeMutablePointer? I tried this without success: struct TheStruct { var a:Int = 0 } var myStruct = TheStruct() var address = UnsafeM...
Anking asked 10/4, 2015 at 8:21

6

Solved

According to this, void* has no RTTI information, therefore casting from void* is not legal and it make sense. If I remember correctly, dynamic_cast from void* was working on gcc. Can you please...
Punkie asked 9/11, 2010 at 6:36

1

Solved

We know that void* holds no information regarding the actual type of the data it points to. However, from cppreference on new and new[] we know that those operators return void*. How come, th...
Telamon asked 28/12, 2019 at 17:51

6

Solved

I have a C++ program: struct arguments { int a, b, c; arguments(): a(3), b(6), c(9) {} }; class test_class{ public: void *member_func(void *args){ arguments vars = (arguments *) (*args); /...
Ers asked 31/10, 2011 at 3:30

© 2022 - 2024 — McMap. All rights reserved.