Quick actions

cmd+k|ctrl+k

Navigation

Languages

Fancy Asserts

Snippet info

Language

C

Visibility

public

Author

evine

Created

2015-12-29T16:43:38Z

Updated

2015-12-29T20:53:58Z

#include <stdio.h>
#include <stdlib.h>

typedef __uint128_t u128;
typedef __uint64_t u64;
typedef __uint32_t u32;
typedef __uint16_t u16;
typedef __uint8_t u8;

typedef __int128_t s128;
typedef __int64_t s64;
typedef __int32_t s32;
typedef __int16_t s16;
typedef __int8_t s8;

typedef __uint32_t b32;


// Switches
#define DEBUG 1

// Dissapearing functions
#if DEBUG
#define Dlog(...)                               \
    printf(__VA_ARGS__)

// TODO:Daniel: Log true asserts as well.
// TODO:Daniel: Break code if complier is correct.
// NOTE:Daniel: ... is a printf string with printf functionality.
#define Assert(Expression,...)                      \
    if(!(Expression))                               \
    {                                               \
        Dlog("Assert   File: %s\n",__FILE__);       \
        Dlog("         Line: %i\n",__LINE__);       \
        Dlog("     Function: %s\n",__FUNCTION__);   \
        Dlog("   Expression: %s\n",#Expression);    \
                                                    \
        if(__VA_ARGS__)                             \
        {                                           \
            Dlog("Error Message: ");                \
            Dlog(__VA_ARGS__);                      \
            Dlog("\n");                             \
        }                                           \
                                                    \
        goto PanicExit;                             \
    }
//#define Assert(Expression) if(!(Expression)) {*(s32 *)0 = 0;} // NOTE:Daniel: Breaks code

#else
#define Assert(Expression,...)
#define Dlog(...)
#endif

int main() {
    u32 Large = 20;
    u32 Small = 500;
    
    //Assert(Large > Small , 0); // NOTE:Daniel: Can take 0 to not print error message
    Assert(Large > Small , "Random printf() talk can go in here, So write \"nice\" things: Large == %i, Small == %i" , Large , Small);
    
    Dlog("Yar");
    
    return 0;
    PanicExit:
    { // NOTE:Daniel: Save state to disk before exit
        
        return 112;
    }
}

INFO