Skip to Content.
Sympa Menu

freetds - Re: [freetds] how to write C

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] how to write C
  • Date: Sat, 1 Dec 2007 09:59:29 -0500

entropy AT freetds.org wrote:
> > memset( ptr, len, '\0')
> >
> > a favorite of mine, not least because '\0' is silly: the value
> > argument is defined as int.
>
> Well the value should go in argument 2, but I don't see any problem with
>
> '\0'. Would you think "memset(ptr, 'x', 23)" was silly? Would
> "memset(ptr, 120, 23)" be clearer? Specifying '\0' makes it explicit
> that "this is a character", and making such things explicit makes code
> easier to read.

I've always understood that 'x' was both clearer than 120 and allowed for
other encodings. So the two are really semantially different. I predict
no one will ever invent an encoding in which '\0' != 0.

I think of the call as "fill buffer with zeros", not "fill buffer with
that value representing the NUL terminator". But I use the '\0' form too
myself, to keep the code consistent.

I wonder how you would feel if GNU decided to add a warning about implicit
promotions of signed character literals in function calls?

> I like the parens, and I easily get a headache from reading
> too much smart-ass code written in the "lean and mean" style without
> them.

Agreed, they're sometimes helpful; it depends on the complexity of the
expression. I object to the compiler's assertion that they're always
needed, which to me is clearly untrue.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page