How to use static_assert to evaluated at compile time in C

2 Answers

0 votes
#include <assert.h>

int main(void)
{
    static_assert(5 + 8 == 13, "Error1 5 + 8 == 13"); 

    static_assert(5 + 8 == 12, "Error2 5 + 8 == 13");

    // Error	C2338	Error2 5 + 8 == 13	D:\test\main.c	7


    return 0;
}



/*
run:


*/

 



answered Apr 26, 2023 by avibootz
0 votes
#include <assert.h>

int main(void)
{
    static_assert(sizeof(int) < sizeof(char), "Error1 int > char");

    // Error C2338	Error1 int > char	3DPlatform	D:\test\main.c  5


    return 0;
}



/*
run:


*/

 



answered Apr 26, 2023 by avibootz

Related questions

1 answer 134 views
1 answer 125 views
1 answer 146 views
...