assert

Posted By: Grat

assert - 06/19/19 14:50

Hi,

how to realize macro assert?

Code
#define ASSERT(expr) if (!(expr)) printf("\nError at line: %d ", __LINE__)


how to get a line in script?

thanks
Posted By: jcl

Re: assert - 06/19/19 14:59

There is no __LINE__ in lite-C, but the rest of the assert macro should work.
Posted By: Grat

Re: assert - 09/22/20 12:14

if anybody want

Code
#include <profile.c>
#define assert(expr,line) if (!(expr)) printf("\nError at line: %d ", line)

// ------
int myDEF_ERR=0;
// -- ALFA --------------
#define ALFA 1

// -- BETA --------------
#define BETA 1
// --- control  
    #ifdef ALFA 
    #ifdef BETA
        myDEF_ERR = 1;
    #endif
    #endif

// -- GAMA --------------


void main(){
    assert(myDEF_ERR>0,22);
}


this code produce:
Quote


protoGen compiling............... ok

Error at line: 22

© 2024 lite-C Forums