It used to be like this:
const size_t buffer_size = 1024; unsigned char buffer[buffer_size];
in C since buffer_size not a "real" constant. Therefore you often see
#define BUFFER_SIZE 1024 unsigned char buffer[BUFFER_SIZE];
instead.
Starting with C99, you can do the first, but not globally. It will not work outside the function (even if static is done). Since a lot of code in the kernel deals with similar constructs, this may be one of the reasons for using a preprocessor.
Note: do not forget about sizeof , it is a very good tool when it comes to the fact that the size constant is not repeated throughout the place, regardless of how the constant was implemented.
unwind
source share