473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Enabling and disabling a macro

I want to create a macro that it must be ignored when NDEBUG is defined.

The macro I've created is

#ifndef NDEBUG
# define ERROR_MESSAGE(s) fprintf(stderr, "%s(): %s\n", __func__, (s));
#else
# define ERROR_MESSAGE(s)
#endif

However, when I checked assert.h to see how the assert() macro was
implement, I ran across

#if defined __cplusplus && __GNUC_PREREQ (2,95)
# define __ASSERT_VOID_CAST static_cast<void>
#else
# define __ASSERT_VOID_CAST (void)
#endif

#ifdef NDEBUG
# define assert(expr) (__ASSERT_VOID_CAST (0))
#else /* Not NDEBUG. */
/* some code */
#endif
Is there any could reason making my macro ((void)0) when I disable it?
Dec 17 '05 #1
3 4688
Giannis Papadopoulos wrote:
I want to create a macro that it must be ignored when NDEBUG is defined.

The macro I've created is

#ifndef NDEBUG
# define ERROR_MESSAGE(s) fprintf(stderr, "%s(): %s\n", __func__, (s));
#else
# define ERROR_MESSAGE(s)
#endif

However, when I checked assert.h to see how the assert() macro was
implement, I ran across

# define __ASSERT_VOID_CAST (void) .... # define assert(expr) (__ASSERT_VOID_CAST (0)) ....

Is there any could reason making my macro ((void)0) when I disable it?


not really. shouldn't hurt anything.

There is a specific expansion list, of six preprocessor tokens,
required for assert() when disabled by the standard - that is ( ( void
) 0 ). You are not required to follow that for your own macros.

Dec 17 '05 #2
In article <dn**********@newsmaster.pub.dc.hol.net>,
Giannis Papadopoulos <ip******@inf.uth.gr> wrote:
I want to create a macro that it must be ignored when NDEBUG is defined.

The macro I've created is

#ifndef NDEBUG
# define ERROR_MESSAGE(s) fprintf(stderr, "%s(): %s\n", __func__, (s));
#else
# define ERROR_MESSAGE(s)
#endif

However, when I checked assert.h to see how the assert() macro was
implement, I ran across

#if defined __cplusplus && __GNUC_PREREQ (2,95)
# define __ASSERT_VOID_CAST static_cast<void>
#else
# define __ASSERT_VOID_CAST (void)
#endif

#ifdef NDEBUG
# define assert(expr) (__ASSERT_VOID_CAST (0))
#else /* Not NDEBUG. */
/* some code */
#endif
Is there any could reason making my macro ((void)0) when I disable it?


First try to compile this using your macros:

if (n == 0)
ERROR_MESSAGE ("n should not be zero");
else
call_function_using_n (n);
Dec 17 '05 #3
Christian Bau wrote:
In article <dn**********@newsmaster.pub.dc.hol.net>,
Giannis Papadopoulos <ip******@inf.uth.gr> wrote:
I want to create a macro that it must be ignored when NDEBUG is defined.

The macro I've created is

#ifndef NDEBUG
# define ERROR_MESSAGE(s) fprintf(stderr, "%s(): %s\n", __func__, (s));
#else
# define ERROR_MESSAGE(s)
#endif

However, when I checked assert.h to see how the assert() macro was
implement, I ran across

#if defined __cplusplus && __GNUC_PREREQ (2,95)
# define __ASSERT_VOID_CAST static_cast<void>
#else
# define __ASSERT_VOID_CAST (void)
#endif

#ifdef NDEBUG
# define assert(expr) (__ASSERT_VOID_CAST (0))
#else /* Not NDEBUG. */
/* some code */
#endif
Is there any could reason making my macro ((void)0) when I disable it?


First try to compile this using your macros:

if (n == 0)
ERROR_MESSAGE ("n should not be zero");
else
call_function_using_n (n);


Yes, you are right, there is an excess ';' at the end of fprintf. And
because I'm always using brackets, I didn't notice it.

Damn copy-paste.. Tnx Christian..

--
one's freedom stops where others' begin

Giannis Papadopoulos
Computer and Communications Engineering dept. (CCED)
University of Thessaly
http://dop.users.uth.gr
Dec 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Lees | last post by:
I want to disable the security warning box that appears when I open a DB. It asks if I want to open this file. It is annoying. I understand that I am suppose to change the macro security...
2
by: HumptyDumpty | last post by:
Does anyone know if there is a problem with re-enabling the Screen Saver after it has been disabled programmatically. I am using the SystemParametersInfo function within User32.dll, and have...
2
by: adeelanjum2001 | last post by:
i am using radiolist box control in my page. when i disable radiolist box when page is displayed first time, that is not ispostback, and when i try to enable it with my javascript code afterwards,...
7
by: John Meyer | last post by:
I have a program where I have to enable or disable a list box based upon a radio button. Is there an "enabled" property on select boxes?
7
by: Vignesh | last post by:
I have tab control which has some TabPages. I want to enable or disable the tabpages based on some condition. It is possible to that. Thanks in advance.
2
by: dougawells | last post by:
Hi- I'm wanting to have a set of radio buttons disabled when a form is displayed, then if they check another specific radio button, those would become enabled. I've tried setting it via...
0
Ali Rizwan
by: Ali Rizwan | last post by:
Hi, How can i control my devices using vb6. Like disabling mouse keyboard speakers etc. Thanx
3
by: D¿ejm | last post by:
Hello, We have a code with lot of printfs. Now I would like to introduce special mode, in which only special messages are displayed and all other are hidden. No macros or replacements please....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.