Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Are bad developer libraries the problem with M$ software?

From: Ali Saifullah Khan <whipaz(at)gem.net.pk>
Date: Fri Nov 22 2002 - 12:27:53 EST

Here is a test done on the return of sizes by sizeof() using pointers.

#include <iostream.h>

int main(void) {
 char *testbuff[1024];

 int len = sizeof(testbuff);
 cout << len << "\n";
 return 0;
}

c:>debug\testbuff
4096

The output from this is 4096 but infact it should be returning 1024. Apparently, using a pointer has multiplied the value of the original size of the testbuff[] buffer by the size of the " pointer " ?

char pointers have a size of 4 bytes.....as is shown when output is 4 bytes using " int len = sizeof((char*)testbuff); "

Do you need help?X

c:>debug\testbuff
4

so sizeof is returning the size of the "first" entity passed to it, that being the size of the pointer. " * "

Whats confusing is when sizeof outputs the value for something like " char * testbuff[] "
Here the macro seems to be multiplying the sizes of entities passed to it, by considering the first entity as the pointer denoted by the asterisk itself " * ", and then taking this value of 4 and multiplying it with the size of the buffer testbuff[] which is 1024, to produce an output of 4096.

Rather strange behaviour. ???
----- Original Message -----
From: <cdavison@nucleus.com>
To: <secprog@securityfocus.com>
Cc: <viega@securesoftware.com>
Sent: Tuesday, November 19, 2002 2:59 AM Subject: Re: Are bad developer libraries the problem with M$ software?

> ----- Original Message -----
the author did use strlen.
>
> > sizeof will return the size of the data type passed to it. So if you
allocated, or passed to you as a pointer, these macros will not work.
>
>
>
>
Received on Mon Nov 25 15:19:52 2002

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:02:44 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library