void

Void in constrast with Unit

久未见 提交于 2019-12-01 15:14:13
问题 I would like to understand which is the difference between these two programming concepts. The first represents the absence of data type and at the latter the type exists but there is no information. Additionally, I recognize that Unit comes from functional programming theoretical foundation but I still cannot understand what is the usability of the unit primitive (e.g., in an F# program). 回答1: The unit type just makes everything more regular. To an extent you can think of every function in F

In Java, can “void” be considered a primitive type?

試著忘記壹切 提交于 2019-12-01 15:12:18
I've noticed eclipse JDT uses void as a primitive type . Can this be considered correct? Pops I find that, in cases like this, you can't beat going to the Java Language Specification. It is pretty clear about the fact that void is not a primitive. First off, void is not in the list of primitive types . Later on, the JLS explicitly states: the Java programming language does not allow a "cast to void" — void is not a type http://java.sun.com/docs/books/jls/third_edition/html/statements.html#5989 (emphasis mine) Furthermore, void appears in the list of keywords , not the list of literals. The

How to check if a void* pointer can be safely cast to something else?

有些话、适合烂在心里 提交于 2019-12-01 06:12:38
Let's say I have this function, which is part of some gui toolkit: typedef struct _My_Struct My_Struct; /* struct ... */ void paint_handler( void* data ) { if ( IS_MY_STRUCT(data) ) /* <-- can I do something like this? */ { My_Struct* str = (My_Struct*) data; } } /* in main() */ My_Struct s; signal_connect( SIGNAL_PAINT, &paint_handler, (void*) &s ); /* sent s as a void* */ Since the paint_handler will also be called by the GUI toolkit's main loop with other arguments, I cannot always be sure that the parameter I am receiving will always be a pointer to s . Can I do something like IS_MY_STRUCT

Can there be a C++ type that takes 0 bytes

久未见 提交于 2019-12-01 05:25:26
I'm trying to declare a C++ variable that takes up zero bytes. Its in a union, and I started with the type as int[0]. I don't know if that is actually zero bytes (although sizeof(int[0]) was 0). I need a better way to declare a 0 byte type, and hopefully one that can be typedefed to something like nullType or emptyType. The variable is in a union, so in the end memory is reserved anyway. I tried void on the off chance it would work, but C++ complained. I'm using Ubuntu 10.10, with a current version of the kernel, and an up-to-date GCC. Here's the union: union RandomArgumentTypesFirst { uint

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

≡放荡痞女 提交于 2019-12-01 03:41:45
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) ? Casting an expression to (void) basically tells the compiler to ignore the result of that expression (after computing it). In your example, each of the expressions (per statement/line) is dynamically allocating memory via the new

Does deleting void pointer guarantee to delete right size? [duplicate]

感情迁移 提交于 2019-12-01 03:34:42
Possible Duplicate: Is it safe to delete a void pointer? Say I have a new allocation to a class called MyClass and allocation is as simple as: MyClass *myClassPtr = new MyClass(); And I store reference to the list of void* where I simply say myListOfPointers.add(static_cast<void*>(myClassPtr)); // this has to be void* And later I release memory so instead of doing: delete myClassPtr I use: delete MyListOfPointer.get(0) (Say myClassPtr reference is at zero-index.) Also, please note that it has to be void* since this list can store different types of pointers so I wouldn't know the type of

Why does void in Javascript require an argument?

给你一囗甜甜゛ 提交于 2019-12-01 03:26:09
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 be passed would be pointless. thefourtheye As per this page https://developer.mozilla.org/en-US/docs

How bad is to use void pointer in std::vector declaration?

蹲街弑〆低调 提交于 2019-12-01 01:55:14
I have two different classes as below: class text { }; class element { }; And I want to store them in the class node : template <typename T> class node { T cargo; std::vector<void*> children; node(T cargo) : cargo(cargo) { }; void add_child(T node) { this->children.push_back((void*) node); } } So I would call the node this way storing both, text and element 's: element div; text msg; node<element> wrapper(div); wrapper.add_child(msg); EDIT : To get back the content I use T typedef type; and convert void pointer to (type*) . I know that's not very elegant nor functional, but I just can't figure

Does deleting void pointer guarantee to delete right size? [duplicate]

空扰寡人 提交于 2019-11-30 23:22:42
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is it safe to delete a void pointer? Say I have a new allocation to a class called MyClass and allocation is as simple as: MyClass *myClassPtr = new MyClass(); And I store reference to the list of void* where I simply say myListOfPointers.add(static_cast<void*>(myClassPtr)); // this has to be void* And later I release memory so instead of doing: delete myClassPtr I use: delete MyListOfPointer.get(0) (Say

Using `void_t` to check if a class has a method with a specific signature

一曲冷凌霜 提交于 2019-11-30 20:23:31
At the moment, I'm using this method to check if a class has a method with a specific signature. After attending Walter E. Brown's metaprogramming CppCon2014 talk , I started wondering if void_t could be used in this particular situation to make the code cleaner and more readable. However I'm having trouble thinking in terms of void_t - so far I understand that void_t can help me determine at compile-time whether or not an expression is valid. Example: template< class, class = void > struct has_type_data_member : false_type { }; template< class T > struct has_type_data_member<T, void_t