Talk:Sizeof

message: 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)
replies: text: 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)
replies: text: That pretty much fixes the parts I was concerned with, thanks --Michael Lynn 08:32, 6 November 2006 (UTC)

message: I re-added the small note about readability. I hope it's in a better place now. I always considered readability to be a huge reason for using sizeof.
:You're probably right, now that I think more about it. Conor H. 17:16, 14 August 2007 (UTC)
thread_title:  Readability 

message: The article is inconsistent in use of parentheses after the sizeof operator. Some examples use the parens, some don't, some leave whitespace and some don't. I'm for removing the parentheses where not strictly required, for reason explained below. Asking politely for your input, before I go around about editing. 
The issue is similar as with `include' or `require' statements in PHP -- using parentheses is superflous (unless following argument is an expression) and seems mostly harmless. However, placing unnecessary parentheses in examples causes many programmers to believe the satement (or the operator) to be a function call, with all the semantics and limitations of calling a function and being evaluated each time the code is ran; this belief then influences coding habits.
Please excuse me not logging in; I'm at work and don't remember my WP password.
:Sounds fine to me. I always use parens just for consistency's sake, but you don't and that's fine, and I agree that it should be consistent. So I say, edit away (not that you need my permission). Conor H. (talk) 01:54, 27 November 2008 (UTC)
thread_title:  Use of parentheses with the sizeof operator 

message: I've made some substantial changes here, and I thought I would explain.
The text states:
It should be noted that, since sizeof is a compile-time operation, it is impossible to use sizeof to determine the size of an array if it cannot be evaluated at compile time.
That's incorrect since C99 introduces variable-length arrays. In that case, the size of the array can only be evaluated at run-time, and sizeof() will be evaluated at runtime.
Then it goes on to say:
In the above example, since the size of the argv array is indeterminate, sizeof(argv) will be equivalent to sizeof(char **) — in other words, the size of the pointer type corresponding to the array, not the amount of memory the array itself (which the pointer refers to) takes.
That's at best misleading. argv isn't an array - it's a pointer (to a pointer). Thus, the size of argv will be the size of a pointer. This has nothing to do with the size of the argv array being indeterminate, and much to do with the way arrays are passed to functions (by decaying into a pointer to the first element). Even if there was an array which had a known number of elements (i.e., not "indeterminate" in size), if you were to pass it to a function, it would still decay into a pointer to the first element and  sizeof() called over the parameter would yield the size of the pointer.
I didn't change the line that said "When sizeof is applied to an array, the result is the size in bytes of the array in memory", but I was slightly unhappy with it since arrays are not somehow special in this respect - sizeof() also returns the size of simple types and structures.
Narj (talk) 21:53, 17 June 2009 (UTC)
thread_title:  Errors in section "Using <code>sizeof</code> with arrays" 

message: According to the Everything you ever wanted to know about C types blog entries by ISO C comittee member Peter Seebach, the sizeof operator returns the size in units of unsigned char, not necessarily bytes. From Part 1: "In C, size is measured in units of unsigned char, and returned as a value of type size_t, which is some unsigned integer type; the size of a type is the number of unsigned char objects it would take to hold all the bits used to store the object. The built-in sizeof operator yields this size." He also gives the example of a 60-bit char, to emphasize the importance of not assuming that chars are bytes.
The article should be changed to reflect this. --Caesar (talk) 14:41, 24 April 2011 (UTC)
replies: text: The term byte is a bit ambiguous is this context.  C defines the byte as "3.6. byte: addressable unit of data storage large enough to hold any member of the basic character set of the execution environment" - IOW, a char.  So they're synonymous from a strict C perspective.  Common modern usage, however, usually assumes bytes to be 8 bits, which is clearly not what sizeof returns (except, of course, on those machines where the C byte - and by extension the C char - are 8 bits).  Rwessel (talk) 15:47, 24 April 2011 (UTC)
replies: text:  You're right. I've made a few changes to point this out; for the sake of not making things over-complicated, byte should probably be used through-out the article, as it is now. --Caesar (talk) 16:48, 24 April 2011 (UTC)
thread_title:  Size in unsigned chars, not bytes 

message: In the first array example, why is the code subtracting sizeof buffer[0]?  The last element of the array will always be overwritten by the \0, so what is the point of avoiding copying a char into that element before it gets overwritten?  — Preceding unsigned comment added by 208.32.11.93 (talk) 17:50, 11 September 2013 (UTC)
replies: text: It's a pretty silly example as it stands, although the technique might have some use if the type of the array was other than char.  Rwessel (talk) 00:40, 13 September 2013 (UTC)
thread_title:  First array example 

message: This has nothing to do with C99.  sizeof(char) has always been 1, even in C89 and K&R.  Further the C standard defines “byte” as a synonym for char.  All versions of the C standard support chars that are not 8-bits in size. And the parenthesis in the changed examples are not required unless the item being passed is a type.  Rwessel (talk) 06:33, 5 May 2015 (UTC)
thread_title:  5-May-2015 Edits by Tony Mach 

message: There has been a bit of a slow motion edit war going on over syntax highlighting in the code samples in this articles.  I'd ask the parties to stop and discuss it here.  This includes myself, although I don't recall either adding or removing highlighting from the article, I have made highlighting-related changes.
I have also removed the cleanup tag - a cleanup tag for a lack of syntax highlighting is pretty excessive.
A couple of comments:  First, syntax highlighting makes most sense on larger chunks of code, and even if syntax highlighting is added to the larger pieces of sample code in this article, it's not necessarily appropriate for *every* sample, especially the one-or-two line samples.
Second, if syntax highlighting is reintroduced (as I write this it's not there), we should use the "cpp" style, and not the "c" style.  As was discussed and decided for C (programming language), the cpp style is more attractive, and has no downsides for use with C code.  Rwessel (talk) 04:48, 8 December 2015 (UTC)
thread_title:  Syntax highlighing 

message: There is currently a discussion at talk:typedef. The thread is Syntax Highlighting. Thank you. Cedar101 (talk) 00:16, 2 September 2020 (UTC)
thread_title:  Syntax highlighting revisited