문제

I m currently preparing a C certification, in the course material relating to pointer NULL, there is this line whch trouble me:

if you want to use the NULL symbol you have to include one of the following header files: stdio.h or stddef.h. The NULL symbol is defined in there.

(Bold are in the source)

Since the or is emphasized, I read it as "never include both". Is it a real norm or is it just one of the (many) flaws in the course material?

도움이 되었습니까?

해결책 3

you can include either one or both. The one to be written first will declare NULL as the first and it wont be declared twice.

다른 팁

It is useless to include both since stdio.h includes stddef.h. But you can include both if you want, since there is a guard to avoid multiple inclusions.

the official place for NULL to be defined is in <stddef.h>. However, on most implementations, you can include <stdio.h> or <string.h> (or quite a few other includes) to pick it up.

It is quite safe to include both, and you should so so if you actually need them (and contrariwise, you shouldn't include <stdio.h> if you don't need it).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top