首页 > 其他 > 详细

c assert函数

时间:2020-03-08 12:35:43      阅读:70      评论:0      收藏:0      [点我收藏+]

条件为false,调用abort函数退出进程,在线程中执行也会导致进程退出

//
// Created by gxf on 2020/3/8.
//
#include "linklist.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>

void printHello();

int main() {
    int a = 1;
    int b = 0;
    pthread_t thread;

    pthread_create(&thread, NULL, printHello, NULL);

    pthread_join(thread, NULL);

    printf("before abort\n");
    abort();
    assert(b < a);
    printf("hello assert\n");


    return 0;
}

void printHello() {
    int k = 1000;
    int i = 0;
    while (1) {
        if (i == 10) {
            assert(k < i);
        }
        i ++;
        printf("hello\n");
        sleep(1);
    }
}

  技术分享图片

 

c assert函数

原文:https://www.cnblogs.com/luckygxf/p/12441409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!