Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

Thread Tools

#define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

Yevgen Muntyan
Posts: n/a
Old Wolf wrote:
> On Feb 10, 3:52 am, Yevgen Muntyan <(E-Mail Removed)>
> wrote:
>> Consider the following macro:
>> #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

> Have you considered:
> #define ALLOCIT(Type) ((Type*) (Type*) (Type *) \
> (&malloc)(sizeof(Type) * 1 + 0 - 0))
> ?

Of course. As well as

#define ALLOCIT(Type) ((Type*)(Type*) malloc (15 * sizeof (Type) + 1)

In fact I am using a better version:

#define ALLOCIT(Type) ((Type*)(char*) malloc (MAX (42, sizeof (Type))))

>> I make a conclusion: void* is evil and must be avoided
>> when possible and easy.

> I go out of my way to use (void *) as much as possible,
> when the type of the storage is not relevant.

Which is irrelevant.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
to malloc or not to malloc?? Johs32 C Programming 4 03-30-2006 10:03 AM
porting non-malloc code to malloc C Programming 3 02-19-2005 05:39 AM
Malloc/Free - freeing memory allocated by malloc Peter C Programming 34 10-22-2004 10:23 AM
free'ing malloc'd structure with malloc'd members John C Programming 13 08-02-2004 11:45 AM
Re: free'ing malloc'd structure with malloc'd members ravi C Programming 0 07-30-2004 12:42 PM