Skip to Content.
Sympa Menu

freetds - Re: [freetds] portable constructions

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Michael Peppler <mpeppler AT peppler.org>
  • To: freetds AT lists.ibiblio.org
  • Subject: Re: [freetds] portable constructions
  • Date: 31 Dec 2002 14:53:04 -0800

On Tue, 2002-12-31 at 14:34, James K. Lowden wrote:
> I often see code like this:
>
> CS_VOID * buffer;
> CS_INT int_val;
> memcpy(buffer, &int_val, sizeof(CS_INT));
>
> I wouldn't use memcpy(). I would cast it:
>
> *(CS_INT*) buffer = int_val;
>
> Is there some reason not to do that? Surely my code is easier to
> understand and requires fewer instructions.

I've used both. I think the latter is potentially open to memory
alignment problems (and a good C compiler might actually optimize away
the call to memcpy()).

Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler AT peppler.org http://www.mbay.net/~mpeppler
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.mbay.net/~mpeppler/resume.html

Attachment: signature.asc
Description: This is a digitally signed message part




Archive powered by MHonArc 2.6.24.

Top of Page