//预处理指令
#ifndef __BASICTEST_CPP__
#define __BASICTEST_CPP__
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define trace(x, format) \
printf(#x " = %" #format "\n", x)
#define trace2(i) trace(x ## i, d)
#define assert(cond) \
if(!cond) _assert(#cond,__FILE__,__LINE__)
//预定义宏 __FILE__
//预处理运算符 #字符串化符 ##加标记 
void _assert(char * cond, char *fname, long lineno){
    fprintf(stderr, "Assertion failed: %s, file %s, line %ld\n",cond, fname, lineno);
    abort();
}

int main(){
    int mmm = 10;
    assert((mmm<11));
    int a[] = {0,1,2,3,4};
    // traverse
    size_t n = sizeof a / sizeof a[0];
    for (size_t i = 0; i < n; i++)
    {
        std::cout<<a[i]<<' ';
    }
    std::cout<<std::endl;

    //pointer
    int *ppp = a+n-1;
    // inverse traverse
    while(ppp>=a){
        std::cout << *ppp--<<' ';
    }
    std::cout<<std::endl;
    ppp = a+n-1;
    for (size_t i = 0; i < n; i++)
    {
        std::cout << ppp[-i]<<' ';
    }
    std::cout<<std::endl;

    //test 2.2
    char s[] = "desolate", *p = s;
    std::cout<<*p++<<std::endl;//d
    std::cout<<*p<<std::endl;//e
    std::cout<<*(p++)<<std::endl;//e
    std::cout<<*p<<std::endl;//s
    std::cout<<(*p)++<<std::endl;//s
    std::cout<<*p<<std::endl;//t
    std::cout<<*++p<<std::endl;//o
    std::cout<<*p<<std::endl;//o
    std::cout<<*(++p)<<std::endl;//l
    std::cout<<*p<<std::endl;//l
    std::cout<<++*p<<std::endl;//m
    std::cout<<++(*p)<<std::endl;//n
    std::cout<<strcmp(s, "detonate")<<std::endl;//0

    int arr[][2][3] = {{{0,1},{2,3}},{{4,5},{6,7}},{{8,9},{10,11}}};
    int (*par)[2][3] = arr;
    void *vp;
    std::cout<<sizeof par<<' '<<sizeof vp<<std::endl;//8
    vp = (char *)arr[0][0];
    std::cout<<sizeof (*par) <<std::endl;//24
    std::cout<<sizeof vp<<std::endl;//8


    std::cout<<"__DATE__: "<<__DATE__<<std::endl;
    std::cout<<"__FILE__: "<<__FILE__<<std::endl;
    std::cout<<"__LINE__: "<<__LINE__<<std::endl;
    std::cout<<"__TIME__: "<<__TIME__<<std::endl;

    int x = 66, x1=12;
    trace(x, c);
    trace2(1);
    std::cout<<int(-2.5)<<std::endl;
}

#endif