Re: Patch proposal

[email protected]
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
On Thu, Jun 16, 2011 at 09:32:52AM +0200, Frediano Ziglio wrote:
>   I would like to include this patch (and follows). It define some
> macro to merge allocation and casting.

Hi Freddy, 

Why do you want to do this?  

Any use of the preprocessor makes the code more obscure.  As someone who
knows the code, it's hard enough to understand/remember macro definitions.
Someone new who'd like to contribute will have a harder time every time he
encounters a macro.  

> see this patch as an example
> 
> 
> diff --git a/src/ctlib/ct.c b/src/ctlib/ct.c
> index e7217a9..9e2f03e 100644
> --- a/src/ctlib/ct.c
> +++ b/src/ctlib/ct.c
> @@ -279,7 +279,7 @@ ct_con_alloc(CS_CONTEXT * ctx, CS_CONNECTION ** con)
>         login = tds_alloc_login();
>         if (!login)
>                 return CS_FAIL;
> -       *con = (CS_CONNECTION *) calloc(1, sizeof(CS_CONNECTION));
> +       *con = tds_zalloc(CS_CONNECTION);
...
> as you can see line is shorter. Do you think tds_allocz is better than
> tds_zalloc?

But here's short enough, and right, and clear:

  +       *con = calloc(1, sizeof(CS_CONNECTION));
  
What's wrong with that?  

I've been writing C code since 1985 and I know how to allocate and free memory
using the C standard library.  I prefer to write and read C code that K&R would
recognize (if not necessarily approve of).  

Regards, 

--jkl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.