[M3devel] assert in Modula-3 C code?

Tony Hosking hosking at cs.purdue.edu
Tue Feb 8 15:27:57 CET 2011


I think I was mistaken.  It does appear to be turned on.

On Feb 8, 2011, at 9:06 AM, Jay K wrote:

> It was recently suspect that asserts aren't enabled in the C code in m3core.h
> I don't think so. I think there might just be a missing check of a return value in m3core/thread/*.m3
> 
> However, if we want to dispell this fear now and forever, we could do e.g.:
> 
> m3core.h:
> 
> M3_DLL_LOCAL
> void
> __stdcall
> M3C__AssertFailed (const char* file, unsigned line, const char* expression);
> 
> #define M3_ASSERT(expr) ((expr) ? ((void)0) ? M3C__AssertFailed ( \
>                         __FILE__, __LINE__, #expression))
> 
> 
> 
> hand.c:
> 
> M3_DLL_LOCAL
> void
> __stdcall
> M3C__AssertFailed (const char* file, unsigned line, const char* expression)
> {
>   fprintf (stderr, "%s(%u): assertion failed: %s\n", file, line, expression);
>   abort ();
> }
> 
> This might slightly reduce quality on some platforms, e.g.:
> 
> Assertion failed: (0), function main, file 1.c, line 2.
> Abort trap
> jbook2:libm3 jay$ cat 1.c
> #include <assert.h>
> int main() { assert(0); return 0; }
> 
> 
> that is -- see how it printed the file name? Anyway, we could get that back too, like
> #if __GNUC__  > whatever
>  #define M3_FUNCTION something
> #elif _MSC_VER > something
>  #define M3_FUNCTION __FUNCTION__
> #else
>  #define M3_FUNCTION 0
> #endif
> 
> 
> ?
> 
> But I think probably using standard assert is adequate or preferable.
> We could #undef NDEBUG in m3core.h, in case someone added to the C compiler on the config files.
> or #ifdef NDEBUG, #error.
> 
>  - Jay
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20110208/32e73a45/attachment-0002.html>


More information about the M3devel mailing list