Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6326847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:10:07+00:00 2026-05-24T17:10:07+00:00

On my implementation of C++ (Visual Studio 2008 implementation) I see the following line

  • 0

On my implementation of C++ (Visual Studio 2008 implementation) I see the following line in <cassert>

#ifdef  NDEBUG
#define assert(_Expression) ((void)0)

I do not understand the need to cast 0 to void. It seems to me that

#ifdef  NDEBUG
#define assert(_Expression) (0)

or even simply

#ifdef  NDEBUG
#define assert(_Expression) 0

would do, considering the contexts in which assert(expr) can be used.

So, what’s the danger of 0 of type int instead of 0 of type void in this case? Any realistic examples?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:10:07+00:00Added an answer on May 24, 2026 at 5:10 pm

    The only purpose of the complicated expression (void)0 is to avoid compiler warnings. If you just had a naked, useless expression, the compiler might warn about an expression that has no effect. But by explicitly casting something to void you indicate that you mean to do this.

    (Think about how confusing it would be to the user if the compiler suddenly said, “Warning: expression 0; has no effect.”, when all you’ve done is switched to release mode.)

    This was also common practice in C, where you’d say (void)printf("Hello"); to tell the compiler that you intentionally chose to ignore the return value of the function.

    The (void) cast is not merely a choice by a particular implementation; it’s required by the C standard. Quoting the 2011 ISO C standard (similar wording appears in the 1990 and 1999 editions):

    If NDEBUG is defined as a macro name at the point in the source file
    where <assert.h> is included, the assert macro is defined simply as

    #define assert(ignore) ((void)0)

    The C++ standard requires the contents of the <cassert> header to be the same as the Standard C <assert.h> header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Visual Studio 2008, the following code will build successfully: void Foo (int x);//Prototype
I have a Visual Studio 2008 Windows Mobile 6 C++ application that is using
I'm using Visual Studio 2008 with Feature Pack 1. I have a typedef like
I have C++/CLI code and I'm using Visual Studio 2008 Team Suite Code Coverage.
Working in Visual Studio 2008 (C#)... I use a List collection to store instances
I want to create a simple JNI layer. I used Visual studio 2008 to
I have a Visual Studio 2008 C# 2.0 CF project where I am implementing
I´m using Visual Studio 2008 / C# and SQL Server 2005 to create a
Possible Duplicate: Visual Studio keeps building everything Visual Studio 2008 keeps rebuilding the entire
I have a Visual Studio 2008 C++ program where I have my own stream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.