-
Notifications
You must be signed in to change notification settings - Fork 173
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
Implement standard assert subroutine and associated macros #72
Comments
I think this is a good step forward. I planned to propose adding optional I suggest everything but the first argument to be Minor nit-pick: |
My primary use for assert was in testing which is why I have the two global variables (num_failed_asserts, and num_asserts). Usually you have several tests you want to perform at one time and want some record of the number of failed tests versus the number of tests and additional information as to when/where the failed test occured. However, I tried to also allow for the case where you want to use assert for error_handling in a given subroutine etc and do a hard abort/stop when an appropriate stop condition was met. A couple of things with my code.
|
I think for testing, it's better to use or develop a more specific framework just for testing. I think the main advantage of the assert macro is to test things like sizes of arrays when entering a subroutine, and other conditions that the code depends on. And in Release mode the macro is not executed, so there is no overhead. |
Have we considered using fypp for assert macros? We already have it as a dependency. |
To clarify: this issue is for Debug time assert statements, that get skipped in Release mode. Testing framework is a different use case, to be discussed in #162. Note however, that a project like @milancurcic, @everythingfunctional I think stdlib should have such a macro. However, the issue is that then by default the files ending with
A third approach is to only do this for files that would use Which approach do you prefer, 1) or 2)? I think I prefer 2), simply because using upper case extension feels old fashioned, I am not aware of any modern language that would require that. See also j3-fortran/fortran_proposals#56. |
I think I would lean towards 2. A standard preprocessor is something Fortran probably should have settled on a long time ago. There are simply too many use cases for macros and preprocessor directives not too. I would be fine if fpm picked a preprocessor and just always used it, whether that file needed it or not. |
@everythingfunctional exactly. See also j3-fortran/fortran_proposals#65 for a related discussion about standardizing a pre-processor. The only issue that I can see is that the typical CPP preprocessor is pretty limited in what it can do, and it does not understand Fortran's syntax. |
Also note that the NAG compilers do not pre-process |
NAG does automatically preprocess .F90 files. Mostly. The issue is on macOS with case insensitive file names as I understand it. But surely that must be a problem for all compilers that decide solely on the basis of the file name? |
@certik Just to understand: According to your proposal some stdlibs files would then contain two different kind of macros: fypp-macros (when needed for generating "generic" interfaces) and cpp-style macros for the asserts? While technically possible (fypp's preprocessor instructions are orthogonal to the cpp instructions), wouldn't it be more to use only one preprocessor? Either cpp or fypp but not both? (And then, in case fypp is choosen, package it with stdlib (#133) to make sure, it does not become an extra dependency)? |
I am not sure. It seems we agree to just stick to I think the best way forward is to simply try a few approaches and see which one works the best. Can fypp handle creating ASSERT like macros? |
Yes, of course, it is possible to write macros which depending on a flag/variable create different codes, see the according exampe. |
Per @certiks request, I propose we extend his stdlib_experimental_error.f90 code to a standard assert subroutine and supplement it with some pre-processor macros. As an example here is my implementation of an assert routine and the associated macros
assertions.f90
assert.txt
The associated preprocessor macros are
assert_macros.txt
Note, these are my implementation of similar routine and macros found in the FTL project
The text was updated successfully, but these errors were encountered: