void-pointers

Cast a Swift struct to UnsafeMutablePointer<Void>

倖福魔咒の 提交于 2019-12-29 05:16:10
问题 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 = UnsafeMutablePointer<Void>(&myStruct) Thanks! EDIT: the context I am actually trying to port to Swift the first example in Learning CoreAudio . This is what I have done until now: func myAQInputCallback(inUserData:UnsafeMutablePointer<Void>, inQueue:AudioQueueRef, inBuffer:AudioQueueBufferRef, inStartTime

Possible to check return type of a function?

▼魔方 西西 提交于 2019-12-25 12:08:46
问题 Let's say I have a function.. void * getValue(...); Is there a way that I check for the return type of a call to getValue(...) ? I plan on using a void* method such as getValue() in a program and the process of my program will be dependent on the return type of getValue(). Is it possible to check for return type? 回答1: You may want to return a structure instead enum valuetype {PCHAR, PSHORT, PINT, PLONG, PLLONG, PFLOAT, PDOUBLE, PLDOUBLE}; struct sometype { enum valuetype vt; void *value; }

What is the effect of casting a function pointer void?

╄→гoц情女王★ 提交于 2019-12-25 08:57:07
问题 So I'm trying to write a buffering library for the 64th time and I'm starting get into some pretty advanced stuff. Thought I'd ask for some proffesional input on this. In my first header file I have this: typedef struct StdBuffer { void* address; } StdBuffer; extern void StdBufferClear(StdBuffer); In another header file that #includes the first header file I have this: typedef struct CharBuffer { char* address; } CharBuffer; void (*CharBufferClear)(CharBuffer) = (void*) StdBufferClear; Will

Problems changing a void pointer value in C

被刻印的时光 ゝ 提交于 2019-12-25 05:06:58
问题 Basically my problem is that i'm trying to change the value inside the valor variable, so that after calling of the cambiar_valor function it chenges to 25. But my problem is that it doesn't chang at all. What am i doing wrong here?. I'm trying to make a really generic function so that depending of the data type i pass to the function it changes dinamically. In this case is an integer type but what i'm trying to do here is to check if i could change the value of the valor variable inside the

casting void* to std::function

陌路散爱 提交于 2019-12-24 11:15:35
问题 I have an issue. I'm trying to convert a void* to std::function. This is just a simple example, any suggestions will be appreciated #.h file class Example { public: Example(); int foo(void* hi); int fooFunc(std::function<int(int, int)> const& arg, int x, int y) { foo(arg.target<void*>(), x, y); return 2; } }; #.cpp file Example::Example() { } int Example::foo(void * func, int x, int y) { //cast back to std::function func(x, y); std::cout << "running in foo: " << a << "\n"; return a; } Every

ios passing a void* into UISaveVideoAtPathToSavedPhotosAlbum in Swift

烈酒焚心 提交于 2019-12-24 03:58:08
问题 I'm new to Swift. I'm trying to use the method signature in my class: func UISaveVideoAtPathToSavedPhotosAlbum(_ videoPath: String!, _ completionTarget: AnyObject!, _ completionSelector: Selector, _ contextInfo: CMutableVoidPointer) The last argument, contextInfo, is a void * in obj-c. I get an NSDictionary not a subtype of CMutableVoidPointer error if I pass a dictionary in Swift. Would appreciate any help with this. I don't know how to pass a void * equivalent argument in Swift without

usage of void pointer in c/c++

老子叫甜甜 提交于 2019-12-24 03:07:33
问题 Hey, I am wondering how void pointers is applied in the real world in terms of making a software more secure, more flexible. For example, I know that void pointers, what pointer it will cast to is hidden to outside, which will make a software more secure. Are there other reasons why you would use void pointers? 回答1: Void pointers don't make the software any more secure. The reason to use void* in c is a form of polymorphism - if you don't know what type the data will be you can pass a void*

Casting from void* to an object array in c++

别说谁变了你拦得住时间么 提交于 2019-12-23 20:11:55
问题 I'm having problems getting this to work, class A { public: A(int n) { a = n; } int getA() { return a; } private: int a; }; int main(){ A* a[3]; A* b[3]; for (int i = 0; i < 3; ++i) { a[i] = new A(i + 1); } void * pointer = a; b = (A* [])pointer; // DOESNT WORK Apparently ISO C++ forbids casting to an array type ‘A* []’. b = static_cast<A*[]>(pointer); // DOESN'T WORK invalid static_cast from type ‘void*’ to type ‘A* []’ return 0; } And i can't use generic types for what i need. Thanks in

Avoid incompatible pointer warning when dealing with double-indirection

ⅰ亾dé卋堺 提交于 2019-12-23 15:44:42
问题 Assuming this program: #include <stdio.h> #include <string.h> static void ring_pool_alloc(void **p, size_t n) { static unsigned char pool[256], i = 0; *p = &pool[i]; i += n; } int main(void) { char *str; ring_pool_alloc(&str, 7); strcpy(str, "foobar"); printf("%s\n", str); return 0; } ... is it possible to somehow avoid the GCC warning test.c:12: warning: passing argument 1 of ‘ring_pool_alloc’ from incompatible pointer type test.c:4: note: expected ‘void **’ but argument is of type ‘char **’

“'void*' is not a pointer-to-object type” in code with no void*'s?

久未见 提交于 2019-12-23 09:50:04
问题 I have a problem in my code. In Xcode or using the C++11 compiler, this code works well. However, when I am submitting this code to an Online Judge, the verdict shows "Compile Error" . I think they use the C++4.7.1 compiler, which when I tried to compile it (using Ideone), it says: prog.cpp: In function 'void printArray(int)': prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to