Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I use the convention "size = number of bytes" (as in sizeof), "count = number of elements" and so my sizeof(x)/sizeof(x[0]) macro is actually called COUNT.


In the BSDs (and some other code bases) the macro is spelled nitems and is common enough to be considered idiomatic.


Thank you. I did not know about this, I've been using the long version. nitems is defined in sys/param.h in OpenBSD and FreeBSD in case anyone is interested.


I always call my version lengthof() to match sizeof.


I use lengthof for lengths of string literals.


I always call mine "countof" to match the "sizeof" naming convention.


https://msdn.microsoft.com/en-us/library/ms175773.aspx - although I'm not sure it's a macro. The nice thing is it's detecting that you actually give it an array.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: