Compile Time Assertions in "C"

3 отговора 217 прегледа
#1

Compile Time Assertions in "C"

Na [линк] predi godina imashe postnat tip za C++ compile time assertsions sus templates... eto i tuka edin variant na C.

Ideata tuka e da nakarame kompilatora da pokazhe po njakuw wid suobshtenieto koeto sme zadali, a ne samo che e wuzniknala greshka pri kompilatzia


#define CASSERT(x) extern int CASSERTFAILED[1], CASSERTFAILED[(x)?1:2]
#define CASSERTMSG(x,msg) extern int CASSERTMSGFAILED_##msg[1], CASSERTMSGFAILED_##msg[(x)?1:2]

CASSERTMSG(sizeof(char)==2,char_must_be_2_bytes);
CASSERT(sizeof(long)==4);
CASSERTMSG(sizeof(short)!=sizeof(int),short_is_the_same_as_int);



To err is human
To stderr is inhuman
Отговор
в отговор на malkia #2

Re: Compile Time Assertions in "C"

heheh :-) hitro!

---
Bingo! Bongo! I don't want to leave the Kongo!
Отговор
в отговор на Skotowydec #3

Re: Compile Time Assertions in "C"

Pochti sam siguren (99.99%) che sam wijdal neshto takowa v SDL.
W momenta sam wazprepyatstwan da prowerya, no da, hitro e.

Отговор
в отговор на FP #4

Re: Compile Time Assertions in "C"

wuw windows.h sushto go ima - no realizatziata tam ne pechata nishto kato greshka, i raboti samo pod MSVC.

To err is human
To stderr is inhuman
Отговор