void

passing different structs to a function(using void *)

戏子无情 提交于 2020-01-03 05:49:06
问题 I need to figure out how to pass two different structs to a function. I tried using void * for the parameter but i am receiving the error: warning: dereferencing 'void *' pointer error: request for member left in something not a structure or union same error for member right here is what i did in general terms(code may not compile). struct A{ char *a; struct A *left, *right; } *rootA; struct B{ char *b; struct B *left, *right; } *rootB; void BinaryTree(void *root, void *s){ if(condition) root

C++ Is “const void” As Return Value More Const-Correct Than “void”? [duplicate]

无人久伴 提交于 2020-01-02 22:25:54
问题 This question already has answers here : Should useless type qualifiers on return types be used, for clarity? (6 answers) Closed 4 years ago . I have become somewhat of a const-correctness fanatic when it comes to programming. I've got const's everywhere (where correct of course). Now I've even started const'ing my void return types. You can't create a void object and therefore you can't assign a value to a void object even if it's const or not, which means the "const" becomes redundant. So

C++ Is “const void” As Return Value More Const-Correct Than “void”? [duplicate]

早过忘川 提交于 2020-01-02 22:25:07
问题 This question already has answers here : Should useless type qualifiers on return types be used, for clarity? (6 answers) Closed 4 years ago . I have become somewhat of a const-correctness fanatic when it comes to programming. I've got const's everywhere (where correct of course). Now I've even started const'ing my void return types. You can't create a void object and therefore you can't assign a value to a void object even if it's const or not, which means the "const" becomes redundant. So

Accessing void pointers in Python (using SWIG or something else)

微笑、不失礼 提交于 2020-01-02 21:21:38
问题 I've been trying to use SWIG to wrap around a simple library that uses ioctl() to populate a structure like the following: struct data { header* hdr; void* data; size_t len; }; data is a pointer to a buffer, len is the length of that buffer. I'm unable to figure out how to convert data to a Python string (or array). Furthermore, I need a way to free that buffer in the destructor. Any suggestions are appreciated. 回答1: Since you say "or something else" in the Q's title -- if you choose to use

Accessing void pointers in Python (using SWIG or something else)

大憨熊 提交于 2020-01-02 21:21:06
问题 I've been trying to use SWIG to wrap around a simple library that uses ioctl() to populate a structure like the following: struct data { header* hdr; void* data; size_t len; }; data is a pointer to a buffer, len is the length of that buffer. I'm unable to figure out how to convert data to a Python string (or array). Furthermore, I need a way to free that buffer in the destructor. Any suggestions are appreciated. 回答1: Since you say "or something else" in the Q's title -- if you choose to use

How to implement an interface member that returns void in F#

我怕爱的太早我们不能终老 提交于 2020-01-01 23:59:08
问题 Imagine the following interface in C#: interface IFoo { void Bar(); } How can I implement this in F#? All the examples I've found during 30 minutes of searching online show only examples that have return types which I suppose is more common in a functional style, but something I can't avoid in this instance. Here's what I have so far: type Bar() = interface IFoo with member this.Bar() = void Fails with _FS0010: Unexpected keyword 'void' in expression_. 回答1: The equivalent is unit which is

C programming: casting a void pointer to an int?

十年热恋 提交于 2019-12-31 10:34:33
问题 Say I have a void* named ptr. How exactly should I go about using ptr to store an int? Is it enough to write ptr = (void *)5; If I want to save the number 5? Or do I have to malloc something to save it? 回答1: You're casting 5 to be a void pointer and assigning it to ptr . Now ptr points at the memory address 0x5 If that actually is what you're trying to do .. well, yeah, that works. You ... probably don't want to do that. When you say "store an int" I'm going to guess you mean you want to

What does “(void) new” mean in C++?

◇◆丶佛笑我妖孽 提交于 2019-12-30 08:13:48
问题 I've been looking at a Qt tutorial which uses a construction I haven't seen before: (void) new QShortcut(Qt::Key_Enter, this, SLOT(fire())); (void) new QShortcut(Qt::Key_Return, this, SLOT(fire())); (void) new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close())); I've tried this without the (void) and it still compiles and works, so what is the purpose of the (void) ? 回答1: Casting an expression to (void) basically tells the compiler to ignore the result of that expression (after computing it)

Why does void in Javascript require an argument?

巧了我就是萌 提交于 2019-12-30 08:11:27
问题 From what I understand, the keyword void in Javascript is some kind of function that takes one argument and always returns the undefined value. For some reason you need to pass it an argument; it won't work without one. Is there any reason why it requires this argument? What is the point? Why won't it work without an argument. The only use I have seen for it is to produce an undefined result. Are there any other uses for it? If not then it would seem that the requirement for an expression to

Is it bad practice to use return inside a void method?

邮差的信 提交于 2019-12-29 02:42:46
问题 Imagine the following code: void DoThis() { if (!isValid) return; DoThat(); } void DoThat() { Console.WriteLine("DoThat()"); } Is it OK to use a return inside a void method? Does it have any performance penalty? Or it would be better to write a code like this: void DoThis() { if (isValid) { DoThat(); } } 回答1: A return in a void method is not bad, is a common practice to invert if statements to reduce nesting. And having less nesting on your methods improves code readability and