sonictotal.blogg.se

Size of a pointer
Size of a pointer









size of a pointer size of a pointer size of a pointer

#define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x))) in the Linux kernel headers although it may be slightly different than the one below: The macro is used in real code though, e.g. Unfortunately C doesn’t do this nearly as well as C++ since you basically have to build it for each different array type you are storing which is cumbersome if you have multiple types of arrays that you need to manage.įor static arrays, such as the one in your example, there is a common macro used to get the size, but it is not recommended as it does not check if the parameter is really a static array. For dynamic arrays ( malloc or C++ new) you need to store the size of the array as mentioned by others or perhaps build an array manager structure which handles add, remove, count, etc.











Size of a pointer