Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use cpp function ASSERT in fortran

Status
Not open for further replies.

raghu81

Technical User
Apr 9, 2008
28
DE
Hi,

I am looking for a way to use the c++ ASSERT function in a fortran code like for ex.,

allocate (a(10,10), stat=memstat)
ASSERT(memstat==0)

I am looking for a way to define the 'ASSERT' function in a header file and include some error msg with line numbers etc. and use it. Can any body help me with this? Thanx in advance.

- raghu_r
 
ASSERT is not a function in C and C++, it's a macros. It's expanded by C preprocessor into C statement (if debug mode on and an expession is evaluated to false then prints diagnostics then calls abort() function). Therefore it's a senseless action to include this C construct in Fortran source.
 
Hi ArkM,

Including error msgs in a Fortran code unnecessarily makes the code lengthy. I found the following cpp code on the net and like to know if it can be used in a Fortran code.

#if FPP_NODEBUG
# define ASSERT(expr) if(.not.(expr))call ASSERT_FAILED(__STRING(expr),__FILE__,__LINE__)
# define FPP_ASSERT
#endif

My question was, how can I use the above code (define it in a .h file?, how to compile, link? and so on) for ex. in a situation like as follows

allocate (a(10,10), stat=memstat)
ASSERT(memstat==0)

- regards,
Raghu




 
This is dependent upon the Fortran compiler. Some Fortran compilers may already have this feature. Which compiler are you using?
 
>Including error msgs in a Fortran code unnecessarily makes the code lengthy.
Code length does not bear a relation to this topic.

>I found the following cpp code on the net and like to know if it can be used in a Fortran code.
No, you can't use this C++ preprocessor directives and macros in Fortran code. The Fortran language does not include C++ preprocessor.

Better look at your Fortran compiler docs (see xwb's post above). However as far as I know some Fortran compilers have ASSERT directives with different semantics.
 
Hi,

I am using Gfortran 4.3 which does not have this feature.

- Raghu.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top