void

Why the out put of below code is Thread[main,5,main]

余生长醉 提交于 2019-12-02 13:22:01
public class test1 { public static void main(String[] args) { // TODO Auto-generated method stub Thread t = Thread.currentThread(); System.out.println(t); } } Why the output of above code is - Thread[main,5,main] ? Please Explain Because thread.toString() returns a string representation of this thread, including the thread's name, priority, and thread group. Returns a string representation of this thread, including the thread's name, priority, and thread group. Source: https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#toString() Because of: /** * Returns a string representation

C : Insert/get element in/from void array

烈酒焚心 提交于 2019-12-02 13:17:53
I have to create a generic array that can contain generic data structures. How can i put a generic structure into an empty slot of my void array? This is my code. struct CircularBuffer { int E; int S; int length; // total number of item allowable in the buffer int sizeOfType; // size of each element in the buffer void *buffer; }; struct CircularBuffer* circularBufferInit(int length, int sizeOfType) { struct CircularBuffer *cb = malloc(sizeof(struct CircularBuffer)); cb->E = 0; cb->S = 0; cb->length = length; cb->sizeOfType = sizeOfType; cb->buffer = malloc(sizeOfType *length); return cb; } int

accessing struct: derefrencing pointer to incomplete type

梦想与她 提交于 2019-12-02 09:49:33
When I'm trying to use and access the pointers to my structs i keep getting the annoying message of "dereferencing pointer to incomplete type" .... For example in my user.h file I have this typedef : typedef struct FacebookUser_t* User; and in my user.c file which includes user.h I have this struct: struct FacebookUser_t {...}; So when I need a pointer to that struct I only use User blabla; it seems to work, and I add it to generic list as Element which is void* and that's the typedef for it in list.h : typedef void* Element; and when I get back a node from the list which contains Element (

How is “void()” useful?

妖精的绣舞 提交于 2019-12-02 07:21:24
You cannot declare a void variable: void fn() { void a; // ill-formed } Yet this compiles: void fn() { void(); // a void object? } What does void() mean? How is it useful? Why is void a; ill-formed, while void() OK? void fn() { void a = void(); // ill-formed } The statement void(); creates a void value and then discards it. (You can't actually do much with a void value other than discard it or return it.) The standard † says in 5.2.3 [expr.type.conv The expression T(), where T is a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified)

Error: 'void' type not allowed here

戏子无情 提交于 2019-12-02 07:19:55
问题 I'm learning to use classes and part of my assignment is to make this Car class. I'm getting an error on line 6 where I attempt to print of the results of the methods within the class. I think this means that I'm attempting to print something that doesn't exist and I suspect it's the mileage method. I tried changing it to return miles, but that didn't work either. Any ideas? public class TestCar { public static final void main(String args[]) { Car c = new Car (); c.moveForward(4); System.out

Error: 'void' type not allowed here

心已入冬 提交于 2019-12-02 07:17:34
I'm learning to use classes and part of my assignment is to make this Car class. I'm getting an error on line 6 where I attempt to print of the results of the methods within the class. I think this means that I'm attempting to print something that doesn't exist and I suspect it's the mileage method. I tried changing it to return miles, but that didn't work either. Any ideas? public class TestCar { public static final void main(String args[]) { Car c = new Car (); c.moveForward(4); System.out.println ("The car went" + c.mileage() + "miles."); // <-- L6 } } class Car { public int miles = 2000;

Void methods cannot return a value

痴心易碎 提交于 2019-12-02 01:14:03
I'm following the CS106A lectures online. I'm going through the code on Lecture 12, but it's giving me errors in Eclipse. This is my code. It seems the error is because of the word void in my main method. I tried deleting the main method, but of course Java can't run without it. I'm a newbie and no one has explained what the String[] args thing really means, but I've been told to just ignore it and use it. I'd appreciate if someone could explain that to me as well. This errors also comes up on the 'toLower' method; no idea what it means: Illegal modifier for parameter toLower; only final is

Return nothing or return void— What exactly does C# do at the end of a void Function() call?

懵懂的女人 提交于 2019-12-01 21:32:15
Consider the following C# function: void DoWork() { ... } The C# documentation states: When used as the return type for a method, void specifies that the method does not return a value . That seems straight-forward enough and, in most cases, that suits as a fair definition. However, for many lower-level languages (i.e. C) "void" has a slightly different meaning. Specifically, all blocks of code must return something . Therefore, void is a representation of the null pointer which is a representation of "nothing". In such a case, you do not need to have a return statement within your code

Is casting to pointers to pointers to void always safe?

空扰寡人 提交于 2019-12-01 21:20:30
#include <stdio.h> void swap(void *v[], int i, int j) { void *tmp; tmp = v[i]; v[i] = v[j]; v[j] = tmp; } int main(void) { char *s[] = {"one", "two"}; printf("%s, %s\n", s[0], s[1]); swap(s, 0, 1); printf("%s, %s\n", s[0], s[1]); return 0; } Output : one, two two, one Warning: no compatible pointer casting, need void**, but char I used this program to simulate the swap function in K&R , to demonstrate the use of the function pointer, and my question is whether the cast of the void pointer is always safe, or if there is any way to replace it. jamesdlin No, it is not necessarily safe to pass a

Why can't an incomplete type be casted to void?

六月ゝ 毕业季﹏ 提交于 2019-12-01 19:23:41
Why does the following code give the following error? Why does the type need to be complete in order to be casted to void ? struct Incomplete; class Class { virtual void foo(Incomplete &incomplete) { (void) incomplete; throw std::logic_error("not implemented"); } }; Error: error C2027: use of undefined type 'Incomplete' see declaration of 'Incomplete' It's a change between C and C++, where Microsoft previously implemented the C rules. As noted in remyabel's answer, that has since been fixed. In C, a cast to void , or simply using an expression as a statement by itself (as in incomplete; ),