|
|||||||||||
|
Re: Are bad developer libraries the problem with M$ software?
From: Glynn Clements <glynn.clements(at)virgin.net>
Date: Mon Nov 25 2002 - 16:07:09 EST Ali Saifullah Khan wrote: > Here is a test done on the return of sizes by sizeof() using pointers.
No, 4096 is definitely correct for an architecture with 32-bit pointers. > Apparently, using a pointer has multiplied the value of the original size of
You have declared testbuff as an array of 1024 pointers to character. Each pointer is 4 bytes, so the array occupies 4096 bytes. If you had instead used: char (*testbuff)[1024]; then testbuff would be a pointer to an array of 1024 characters, so sizeof(testbuff) would be 4, and sizeof(*testbuff) would be 1024. Note, however, that (testbuff + 1) would point at memory 1024 bytes further on than testbuff itself (i.e. one array of 1024 characters further on). OTOH, if you had just used: char testbuff[1024]; then sizeof(testbuff) would be 1024. However, in most contexts, the symbol "testbuff" would be implicitly cast to a pointer to character, as if you had written &testbuff[0]. Then, sizeof(&testbuff[0]) would be 4. All of this is adequately explained in chapter 5 of K&R, BTW. > char pointers have a size of 4 bytes.....as is shown when output is 4 bytes
Not at all strange, once you understand C (in particular, the syntax of data declarations). -- Glynn ClementsReceived on Mon Nov 25 20:57:56 2002 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:02:44 EDT |
||||||||||
|
|||||||||||