Talk:Sizeof
From Wikipedia, the free encyclopedia
When you discuss sizeof you make reference to sizeof telling you the number of octets something is. this is not correct, an octet refers to an 8 bit byte, but not all platforms have this (e.g. some machines on the old PDP line), all sizeof is in units of sizeof(char) which is defined to be 1, you have to use limits.h to look at CHAR_BIT to see the number of bits in the byte...so I think this article should be changed to remove the references to octets as they are not portable, and replace them with the word byte or even character, also the example which does a sizeof(c) where c is a char is only a good example if you are demonstrating that sizeof(char) is always defined to be 1 --Michael Lynn 02:34, 2 November 2006 (UTC)
- Changed to (hopefully) incorporate the best of both worlds :) (i.e. sizeof(char) is always 1 and sizes are in terms of bytes) Conor H. 02:19, 6 November 2006 (UTC)
- That pretty much fixes the parts I was concerned with, thanks --Michael Lynn 08:32, 6 November 2006 (UTC)
[edit] Biased towards C89
I think the article was written solely with C89 in mind. Variable length arrays are not mentioned. In such a case, sizeof(a[n]) is evaluated at run-time, so it's not a compile-time constant in all cases. Another important use is mentioned either: sizeof(a) / sizeof(a[0]) is used to calculate the number of elements in an array. I'm not really interested in this article though because all of this explained in the not-so-long standard (the last draft is freely available) and anyone who's calling himself a C programmer should have read it anyway. --82.141.60.27 16:58, 31 December 2006 (UTC)
- find me a compiler that is fully compliant with the new standard and then maybe we can talk, but you're not going to find a real compiler that is because it includes so many stupid things that its not going to happen --Michael Lynn
- You, Sir, are a blatant shame for Wikipedia. If you want to spout nonsense, why don't you write it in your own blog instead of spreading false information instead abusing the resources of Wikipedia. I make you in person liable for the extremely crappy quality of C code in general caused by wanna-be developers incapable of proper reading, learning and instead relying on charlatans like you.
-
- wow, strong words for an anonymous coward... --Michael Lynn 00:34, 2 February 2007 (UTC)
Anyone who wants to code in C should read the standard himself. It's not that large, we're not talking about C++. Competent C wizards can be found on comp.lang.c and there's a huge archive of intelligent enlightening postings there, freely accessible at groups.google.com. Unfortunately, most other web sources have the same low standards as this one. --82.141.49.109 17:42, 1 February 2007 (UTC)