TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Paul Haggart
from: Ed Blackman
date: 1995-12-23 04:41:40
subject: I`m confused about a snippet of cod

On  in a message to Daniel Davis, Paul Haggart wrote:

DD>    cTest = (PCHAR) malloc(12);

PH> I'm no expert, but it looks like you're allocating memory for 12
PH> char pointers?  Is that what you intended?
PH> I always use 'malloc (12 * sizeof(char));' just to be sure I'm
PH> getting the size I want.

Paul, if you ever run into a C compiler where sizeof(char) isn't
one, throw it out immediately.  To describe it as broken would be
charitable.

On the other hand, using (12 * sizeof(char)) is a good idiom from
the documentation standpoint, and there shouldn't be any runtime
penalty.


Ed Blackman

... "Welcome to Hell.  Here's your copy of Windows95." - Satan
--- OMX/Blue Wave/OS2 v2.20
* Origin: Blackman/Strayer '96 Campaign HQ (910) 425-5610 (1:3634/22.42)
SEEN-BY: 270/101 620/243 711/401 409 410 413 430 808 809 934 955 712/407 515
SEEN-BY: 712/517 628 713/888 800/1 7877/2809
@PATH: 3634/22 37 38 3615/50 396/1 270/101 712/515 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™.