C language (void*) 0 and (void) 0

Source: Internet
Author: User
Tags define null null null
A few days ago I saw a macro, and it was probably like this:
#define ASSERT_PARAM (expr) (expr)? (void) 0:assert_failed ((U8 *) __file__, __line__))

The meaning of the code is simple, the key is the use of that (void) 0, I was the first time to see

When I use void, there are two things:
1. Put in front of the function, emphasizing that the function has no return value, that is, the function cannot be the right value
such as: void fun (int x);
2. Place the function parameter inside, emphasizing that the function has no parameters
such as: int fun (void);

Another usage is:
#define NULL ((void*) 0)

This is, of course, the way null NULL pointers are defined (inside stdlib.h).

But, above the macro (void) 0, at first it really made me feel a little strange, do not know what to do, calm down and think about.

It turns out that the purpose of the macro is to prevent the macro from being used as an rvalue, and (void) 0 cannot itself be the right value, because void is not a real type!

C language (void*) 0 and (void) 0

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.