void

What is the purpose of List<Void>?

我们两清 提交于 2019-12-03 11:32:58
问题 I didn't even know this was doable, but I saw while perusing some code online a method with a signature like this: public List<Void> read( ... ) ... What? Is there ever a reason to do this? What could this List even hold? As far as I was aware, it's not possible to instantiate a Void object. 回答1: It is possible that this method signature was created as a by-product of some generic class. For example, SwingWorker has two type parameters, one for final result and one for intermediate results.

What does—or did—“volatile void function( … )” do?

两盒软妹~` 提交于 2019-12-03 10:47:05
I've seen How many usage does "volatile" keyword have in C++ function, from grammar perspective? about use of the volatile keyword on functions, but there was no clear explanation of what Case 1 from that question did. Only a statement by one of the respondents that it seemed pointless/useless. Yet I cannot quite accept that statement, since the AES software implementations for GNUC have been used for literally years, and they have a number of functions like this: INLINE volatile void functionname( /* ... */ ) { /* ... */ asm( /* ... */ ) // embedded assembly statements /* ... */ } There has

How to delete void pointer?

梦想的初衷 提交于 2019-12-03 10:22:13
Is there anything wrong when deleting an object like this in C++? MyCls* c = new MyCls(); void* p = (void*)c; delete (MyCls*)p; This as written is legal. The cast back to MyCls* is critical. Without that, you will invoke undefined behavior--the MyCls destructor will not be called, and other problems may arise as well (such as a crash). You must cast back to the correct type. Also note that this can be complicated if multiple inheritance is involved and multiple casts are used. Your casts must "match" in either direction. If your code is structured such that you won't know the type at the time

public static void main () access non static variable

故事扮演 提交于 2019-12-03 05:11:52
问题 Its said that non-static variables cannot be used in a static method.But public static void main does.How is that? 回答1: No, it doesn't. public class A { int a = 2; public static void main(String[] args) { System.out.println(a); // won't compile!! } } but public class A { static int a = 2; public static void main(String[] args) { System.out.println(a); // this works! } } or if you instantiate A public class A { int a = 2; public static void main(String[] args) { A myA = new A(); System.out

Casting a void pointer to a struct

℡╲_俬逩灬. 提交于 2019-12-03 04:48:53
I started feeling comfortable with C and then I ran into type casting. If I have the following defined in an *.h file struct data { int value; char *label; }; and this in another *.h file # define TYPE void* How do I cast the void pointer to the struct so that I can use a variable "TYPE val" that's passed into functions? For example, if I want to utilize the value that TYPE val points to, how do I cast it so that I can pass that value to another functions? (struct data*)pointer will cast a pointer to void to a pointer to struct data . Typecasting void pointer to a struct can be done in

Call a void* as a function without declaring a function pointer

旧时模样 提交于 2019-12-03 02:37:07
I've searched but couldn't find any results (my terminology may be off) so forgive me if this has been asked before. I was wondering if there is an easy way to call a void* as a function in C without first declaring a function pointer and then assigning the function pointer the address; ie. assuming the function to be called is type void(void) void *ptr; ptr = <some address>; ((void*())ptr)(); /* call ptr as function here */ with the above code, I get error C2066: cast to function type is illegal in VC2008 If this is possible, how would the syntax differ for functions with return types and

What is the purpose of List<Void>?

孤街浪徒 提交于 2019-12-03 01:01:48
I didn't even know this was doable, but I saw while perusing some code online a method with a signature like this: public List<Void> read( ... ) ... What? Is there ever a reason to do this? What could this List even hold? As far as I was aware, it's not possible to instantiate a Void object. It is possible that this method signature was created as a by-product of some generic class. For example, SwingWorker has two type parameters, one for final result and one for intermediate results. If you just don't want to use any intermediate results, you pass Void as the type parameter, resulting in

C programming: casting a void pointer to an int?

耗尽温柔 提交于 2019-12-02 20:35:50
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? 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 actually store the integer value 5 in the memory pointed to by the void* . As long as there was enough memory

public static void main () access non static variable

萝らか妹 提交于 2019-12-02 19:33:50
Its said that non-static variables cannot be used in a static method.But public static void main does.How is that? No, it doesn't. public class A { int a = 2; public static void main(String[] args) { System.out.println(a); // won't compile!! } } but public class A { static int a = 2; public static void main(String[] args) { System.out.println(a); // this works! } } or if you instantiate A public class A { int a = 2; public static void main(String[] args) { A myA = new A(); System.out.println(myA.a); // this works too! } } Also public class A { public static void main(String[] args) { int a = 2

warning: control reaches end of non-void function [-Wreturn-type]

怎甘沉沦 提交于 2019-12-02 13:40:06
I got a piece of code such that: int check(int d, char arr[9][9], int rep_arr[45][3]) { int p = findProb(d, arr, rep_arr, 0) ; if (isIdeal(d, arr) == 1) { print_array(d,arr) ; return 1 ; } else if(isIdeal(d,arr) == 0 && p == 0){ printf("Fail\n") ; return 0 ; } else if (isIdeal(d, arr) == 0 && p != 0) { #do something recursively.. } where isIdeal(d, arr) can only be equal to 0 or 1 and p can be equal to 0 or another integer . However, the compiler gives me the error that given in the title. Later I added return 0 at the end of that piece of code. Now it works but didn't work in a functional