TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Jonathan De Boyne Pollar
from: Michael Douglass
date: 1994-06-16 13:39:16
subject: setmem and memset

JDBP>ZZ>
    >  > char *myChar=new char[20];
    >  > memset(myChar,0,sizeof(myChar));
    >  >
    >  > Oh, methinks I see!  The size of myChar is 4 because it is a pointer!
    >  > Where I was expecting 20... So I should have used sizeof(*myChar)!!!
    >ZZ>

JDBP>  BZZZT!  Wrong !  In this case, sizeof(*myChar) is 1, since myChar is
    >  pointing to a single character.

JDBP>  You cannot use sizeof() and dynamically allocated memory in this way.
    >  Either use a fixed-size array, or use a constant as the parameter to
    >  both the allocation and the memset.

JDBP>  BTW, ever heard of calloc() ?

Sure, but I always thought that the "new" operator was supposed to be
the greatest thing to be added to C++.  Did I miss something?

Michael Douglass
___
 .Mike's Mail Internet:   MICHAEL.DOUGLASS{at}LCHANCE.SAT.TX.US

--- Maximus/2 2.01wb

* Origin: The Rock BBS--410Meg, i486/33, ZyXEL v32bis. (1:387/31)
SEEN-BY: 54/54 620/243 632/348 640/820 690/660 711/409 413 430 807 808 809
SEEN-BY: 711/934 712/353 623 713/888 800/1 2442/0
@PATH: 387/31 1102 3615/50 229/2 2442/0 711/409 54/54 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.