Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NDEBUG macro defined in a header file #353

Open
mrcdr opened this issue May 6, 2020 · 2 comments
Open

NDEBUG macro defined in a header file #353

mrcdr opened this issue May 6, 2020 · 2 comments

Comments

@mrcdr
Copy link

mrcdr commented May 6, 2020

Dear developers,

I faced a problem that the NDEBUG macro defined here:

ITensor/itensor/global.h

Lines 76 to 80 in 9afc9ea

#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG //turn off asserts
#endif
#endif

disabled any assert(), placed even in my own code.

I finally noticed that the DEBUG (or -DDEBUG option) stops the definition (apparently). But I think it's better not to define such important macros inside library header files, or the macro leaks into every files which include the header file and users may lose control of assert() in their own code. Moreover, it's dangerous that once users have forgot the -DDEBUG option, every assertion checks would seem like always passed and failures would be hidden.

If there are no other problems, could you stop defining the NDEBUG macro inside the header file?

Thank you for your useful and well-designed library!

mrcdr

@emstoudenmire
Copy link
Contributor

Hi, thanks for pointing this out. I put it into ITensor a long time ago, and had not recently revisted what would be the best practice here.

After thinking through it some, probably the best move for ITensor is to just become agnostic about the whole assert system, including not to use asserts at all in ITensor library code. That way, we won't be forced to define NDEBUG so that we can be sure asserts are definitely turned off within ITensor library code (because the asserts won't exist in the first place).

Appreciate you letting us know about this, because I can see how it's confusing. For now, please set NDEBUG in your own code as you wish, and we will try to get ITensor to be orthogonal to the assert system in the very near future.

@mrcdr
Copy link
Author

mrcdr commented May 12, 2020

Thank you for your reply.

I'm glad to share the point. I will keep my asserts and use the NDEBUG just for my code.

I leave this post open, so please close it at your convenience.

Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants