How to stop a program in compile time when the size of an array is less than a specific size in C

1 Answer

0 votes
#include <stdio.h>
#include <assert.h>

int main()
{
    char p[1] = "";

    assert(sizeof p >= 2);

    return 0;
}



/*
run:

Assertion failed: sizeof p >= 2, file C:\src\main.c, line 8

*/

 



answered Jul 31, 2024 by avibootz

Related questions

1 answer 67 views
1 answer 178 views
1 answer 81 views
...