Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22145

Why is [static 1] not used everywhere in C?

$
0
0

I saw a Video about modern C programming, and one topic was that when you use [static 1] with a parameter, it indicates to the reader and the compiler that a pointer should never be NULL.

You would use it like this:

void foo(int my_ptr[static 1]) {    // my_ptr should never be NULL}

instead of:

void foo(int* my_ptr) {    // my_ptr can be NULL}

If you enable -Wnonnull, it even throws a warning when you pass NULL to the first option.My question is, why is this not common practice and used everywhere?

I don't think this can or should replace NULL checks, but it certainly would be useful, nevertheless, IMO.

I also heard that compilers might remove NULL checks if they see that the pointer should never be NULL because of the [static 1], which would be bad, but I don't know if this is true.


Viewing all articles
Browse latest Browse all 22145

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>