typedef of C + + void *handle

Source: Internet
Author: User

When writing code and reading code, you often see this code: typedef void *handle, where is it sacred? How to understand it?

Do not understand it, feel it is very magical, know it later, it is a typedef definition, but is the void* type, that is, handle equivalent to void *, we can call it in the handle of the skin of the pointer (PS: pointer and handle is a difference, in this say nonsense);

For void*, because it is a function parameter or function return value, can accept any kind of pointer; that is, the pointer is accepted (so open, Aha). However, when applied, it should be noted that void * must point to a specific type;

void * HAPPYPT;
int* pi=static_cast<int*>happypt;; Attention, here specifically to the int* Oh!

The specific usage is as follows:

1. Do you remember it?

void * __cdecl memset (_out_opt_bytecapcount_ (_size) void * _DST, _in_ int _val, _in_ size_t _size);

This is the prototype of this function, where you can memset void* to Handle,memset is to transfer the address of the beginning of the N-byte value of all assigned to a specific value, so there is no need to know what type of pointer, with the void type pointer instead. When used as a parameter, we generally do not care about the type of address passed in;

When used as a return value, usually returns an address, as to what you want to do with this address you decide, the most common is malloc, which returns the void type pointer as the first address of the allocated memory area, as to what type, it needs the user to specify.

Example

typedef void *handle;
HANDLE m_exitthreadevent;
M_exitthreadevent = CreateEvent (null,false,false,null);


HANDLE CreateEvent (
Lpsecurity_attributes Lpeventattributes,
BOOL bManualReset,
BOOL Binitialstate,
LPTSTR lpname
);

typedef of C + + void *handle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.