Skip to Content.
Sympa Menu

freetds - Re: [freetds] cast to void?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: christos AT zoulas.com (Christos Zoulas)
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] cast to void?
  • Date: Tue, 4 Dec 2007 12:22:19 -0500

On Dec 4, 4:42pm, Frediano.Ziglio AT vodafone.com ("ZIGLIO, Frediano, VF-IT")
wrote:
-- Subject: Re: [freetds] cast to void?

| >
| > Christos Zoulas wrote:
| > > On Dec 3, 7:29pm, daniel.junkmail AT gmail.com ("Daniel Corbe") wrote:
| > > -- Subject: Re: [freetds] cast to void?
| > >
| > > | Most likely to squash a warning on some random crappy compiler.
| > > | Believe it or not not all compilers follow the standard
| > religiously.
| > >
| > > I've yet to see a compiler that gives a warning on that...
| >
| > I'm sorry about the noise.
| >
| > It's my own code and my own friendly GNU C compiler. I
| > thought Frediano
| > had changed it. (Sorry, Freddy!)
| >
| > memset((void*)pnullrep->bindval, ' ', bindlen);
| >
| > bindval is defined as
| >
| > const BYTE *
| >
| > and the compiler issues a warning if you pass a const pointer
| > to memset,
| > as well it should. This is the one place where the data pointed to by
| > bindval is set to something; everywhere else it's read-only.
| >
| > Next time, I think I'll compile first and post second.
| >
|
| Mmm.... why this cast is needed?? If we found you have to allocate and
| initialize bindval we should have a no-const pointer (returned by
| malloc) around. Personally I like the distinction made in C++ that use
| const_cast instead of C style casts... but we are in C.
|
| I also don't understand why we need to allocate some memory in order to
| return NULLs... dbgetnull is called only by _set_null_value. Perhaps
| _set_null_value should do all the job without allocation stuff?? But...
| bindval should not be always initialized?? to_free is used only to pass
| data from dbgetnull to _set_null_value, perhaps merging dbgetnull and
| _set_null_value we can remove this field.
| I noted also that we defined a new NULLREP structure with a field
| (capability) that we don't use at all.
|
| Why we need a initialize_default_null_representations if
| default_null_representations can be initialized statically (and be
| const)?
|
| Is correct dbsetnull for VARYBINBIND/VARYCHARBIND?? Perhaps we should
| copy the entire structure?? I think we don't even support these stranges
| types...
|
| I have a bit of headache... I can do only suppositions...

I agree with Freddy, we should not be doing const-castaways unless it is
absolutely necessary. It is better to declare the pointer non const. Mind
you, if you turn on -Wcast-qual on gcc it will produce a warning on the
const cast-away casts... Perhaps we should just turn on more compiler
warnings to prevent this in the future.

christos




Archive powered by MHonArc 2.6.24.

Top of Page