Skip to Content.
Sympa Menu

freetds - Re: [freetds] [PATCH] VMS build update

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT schemamania.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] [PATCH] VMS build update
  • Date: Sat, 6 Nov 2004 18:32:00 -0500

"Craig A. Berry" <craigberry AT mac.com> wrote:
> James K. Lowden wrote:
> > - if (freopen(options.input_filename, "r", stdin) < 0) {
> > + if ((int)freopen(options.input_filename, "r", stdin) < 0) {
> >
> > Could I change all these to:
> >
> > if (freopen(options.input_filename, "r", stdin) < (FILE*)0) {
> >
> > I think that's more honest.
>
> It looks like the compiler will take that, though it surprises me that
> it doesn't complain about comparing zero to an unsigned value. A pointer
> can't be negative can it?

Not only can it not be negative, the code is wrongo. As you noted,
freopen(3) and friends return NULL, not 0 (where NULL is an
implementation-defined macro representing the "null pointer").

The code should be:

if (freopen(options.input_filename, "r", stdin) == NULL)

cf. http://www.vmunix.com/~gabor/c/draft.html sections 6.2.2.3 and 7.1.6.


That's supposed to work, right? Is you compiler happy with that?

> HOWEVER, as I belatedly look at the docs, my CRTL documentation and C99
> agree that fopen and freopen both return NULL on failure, not a negative
> number. So apparently what we really should be discussing is changing
> them all to "== (FILE*)NULL".

It's supposed to be unnecessary to cast a void* or NULL to anything. ISTR
one can use 0 for any null pointer, but perhaps that is wrong or out of
date.

I think we are approaching the truth, albeit perhaps asymptotically. ;-)

--jkl





Archive powered by MHonArc 2.6.24.

Top of Page