[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

what's meaning of this ?

Tommy

8/15/2008 11:45:00 AM

struct stat *stats IF_LINT (= 0);

I don't know why "IF_LINT (= 0)" is needed ?

Source is df.c of df program on Linux coreutils-5.2.1\coreutils-5.2.1\src

Thanks!


34 Answers

vippstar

8/15/2008 11:48:00 AM

0

On Aug 15, 2:45 pm, "Tommy" <oract...@gmail.com> wrote:
> struct stat *stats IF_LINT (= 0);
>
> I don't know why "IF_LINT (= 0)" is needed ?

Syntax error, constraint violation that requires a diagnostic message.

> Source is df.c of df program on Linux coreutils-5.2.1\coreutils-5.2.1\src
>
> Thanks!

ask some more relevant newsgroup then. comp.lang.c discusses ANSI/ISO
C.

pete

8/15/2008 11:50:00 AM

0

Tommy wrote:
> struct stat *stats IF_LINT (= 0);
>
> I don't know why "IF_LINT (= 0)" is needed ?
>
> Source is df.c of df program on Linux coreutils-5.2.1\coreutils-5.2.1\src

IF_LINT appears to be a function like macro.

The answer to your question is: "What is IF_LINT?"

My first guess is that under a certain circumstance,
perhaps if lint is being used,
the object is initialized upon declaration.

--
pete

James Kuyper

8/15/2008 1:45:00 PM

0

vippstar@gmail.com wrote:
> On Aug 15, 2:45 pm, "Tommy" <oract...@gmail.com> wrote:
>> struct stat *stats IF_LINT (= 0);
>>
>> I don't know why "IF_LINT (= 0)" is needed ?
>
> Syntax error, constraint violation that requires a diagnostic message.

Even if preceeded by a suitable definition of a function-like macro
named IF_LINT()? It is a very common convention that identifiers in
all-caps are generally macros, so that's something you should at least
have thought about.

richard

8/15/2008 4:18:00 PM

0

In article <g83ps2$9md$1@news.cn99.com>, Tommy <oract666@gmail.com> wrote:

> struct stat *stats IF_LINT (= 0);
>
> I don't know why "IF_LINT (= 0)" is needed ?

Presumably it's a macro that expands to "= 0" if you're using lint (a
C checker) and nothing otherwise. And presumably this is because lint
wrongly complains about the variable being uninitialised otherwise.

-- Richard

--
Please remember to mention me / in tapes you leave behind.

Richard Heathfield

8/15/2008 4:29:00 PM

0

Richard Tobin said:

> In article <g83ps2$9md$1@news.cn99.com>, Tommy <oract666@gmail.com>
> wrote:
>
>> struct stat *stats IF_LINT (= 0);
>>
>> I don't know why "IF_LINT (= 0)" is needed ?
>
> Presumably it's a macro that expands to "= 0" if you're using lint (a
> C checker) and nothing otherwise. And presumably this is because lint
> wrongly complains about the variable being uninitialised otherwise.

s/wrongly/rightly/

--
Richard Heathfield <http://www.cpax....
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/goog...
"Usenet is a strange place" - dmr 29 July 1999

Keith Thompson

8/15/2008 4:37:00 PM

0

pete <pfiland@mindspring.com> writes:
> Tommy wrote:
>> struct stat *stats IF_LINT (= 0);
>> I don't know why "IF_LINT (= 0)" is needed ?
>> Source is df.c of df program on Linux
>> coreutils-5.2.1\coreutils-5.2.1\src
>
> IF_LINT appears to be a function like macro.
>
> The answer to your question is: "What is IF_LINT?"
>
> My first guess is that under a certain circumstance,
> perhaps if lint is being used,
> the object is initialized upon declaration.

That's my conclusion as well. Searching the coreutils source tree for
"IF_LINT" would probably tell you something useful.

Further speculation: the line expands to
struct stat *status;
if lint is *not* being used, and to
struct stat *status = 0;

if lint *is* being used. (lint is a program, separate from the
compiler, that analyzes source code for possible problems but doesn't
generate code; there are numerous versions.) Probably lint complains
that status might be used before it's set if the initialization isn't
there. Probably the author is sufficiently confident that it *isn't*
used before being set that he prefers to omit the initialization for
actual compilation. Possibly he uses something like valgrind to
verify at execution time that status is never actually used before
being set, and the initialization would prevent valgrind from
detecting a problem.

(If the author *isn't* using something like valgrind, then omitting
the initialization only when not using lint would be IMHO a foolish
microoptimization.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson

8/15/2008 4:51:00 PM

0

Richard Heathfield <rjh@see.sig.invalid> writes:
> Richard Tobin said:
>> In article <g83ps2$9md$1@news.cn99.com>, Tommy <oract666@gmail.com>
>> wrote:
>>> struct stat *stats IF_LINT (= 0);
>>>
>>> I don't know why "IF_LINT (= 0)" is needed ?
>>
>> Presumably it's a macro that expands to "= 0" if you're using lint (a
>> C checker) and nothing otherwise. And presumably this is because lint
>> wrongly complains about the variable being uninitialised otherwise.
>
> s/wrongly/rightly/

Maybe. Or perhaps the variable really is never used without first
having a value assigned to it, but lint isn't clever enough to prove
this so it issues a warning.

See my other response in this thread for a (perhaps) plausible reason
for making the initialization conditional.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Richard Heathfield

8/15/2008 5:11:00 PM

0

Keith Thompson said:

> Richard Heathfield <rjh@see.sig.invalid> writes:
>> Richard Tobin said:
>>> In article <g83ps2$9md$1@news.cn99.com>, Tommy <oract666@gmail.com>
>>> wrote:
>>>> struct stat *stats IF_LINT (= 0);
>>>>
>>>> I don't know why "IF_LINT (= 0)" is needed ?
>>>
>>> Presumably it's a macro that expands to "= 0" if you're using lint (a
>>> C checker) and nothing otherwise. And presumably this is because lint
>>> wrongly complains about the variable being uninitialised otherwise.
>>
>> s/wrongly/rightly/
>
> Maybe. Or perhaps the variable really is never used without first
> having a value assigned to it, but lint isn't clever enough to prove
> this so it issues a warning.

Um, my point was only that the complaint is accurate - the variable /is/
uninitialised (if we have glarked IF_LINT correctly, which seems likely).

Whether the complaint is justified is another matter. But it is certainly
correct.

--
Richard Heathfield <http://www.cpax....
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/goog...
"Usenet is a strange place" - dmr 29 July 1999

richard

8/15/2008 5:47:00 PM

0

In article <JLidnSVEmMw0MDjVnZ2dnUVZ8q2dnZ2d@bt.com>,
Richard Heathfield <rjh@see.sig.invalid> wrote:

>> Presumably it's a macro that expands to "= 0" if you're using lint (a
>> C checker) and nothing otherwise. And presumably this is because lint
>> wrongly complains about the variable being uninitialised otherwise.

>s/wrongly/rightly/

It's certainly true that "struct stat *stats" does not initialise the
variable. But I didn't say lint was wrong about the variable being
uninitialised, I said it was wrong to complain. Whether it's right to
complain about this depends on the rest of the program, and since the
author used the macro we can assume that it's wrong.

-- Richard
--
Please remember to mention me / in tapes you leave behind.

Keith Thompson

8/15/2008 6:58:00 PM

0

Richard Heathfield <rjh@see.sig.invalid> writes:
> Keith Thompson said:
>> Richard Heathfield <rjh@see.sig.invalid> writes:
>>> Richard Tobin said:
>>>> In article <g83ps2$9md$1@news.cn99.com>, Tommy <oract666@gmail.com>
>>>> wrote:
>>>>> struct stat *stats IF_LINT (= 0);
>>>>>
>>>>> I don't know why "IF_LINT (= 0)" is needed ?
>>>>
>>>> Presumably it's a macro that expands to "= 0" if you're using lint (a
>>>> C checker) and nothing otherwise. And presumably this is because lint
>>>> wrongly complains about the variable being uninitialised otherwise.
>>>
>>> s/wrongly/rightly/
>>
>> Maybe. Or perhaps the variable really is never used without first
>> having a value assigned to it, but lint isn't clever enough to prove
>> this so it issues a warning.
>
> Um, my point was only that the complaint is accurate - the variable /is/
> uninitialised (if we have glarked IF_LINT correctly, which seems likely).
>
> Whether the complaint is justified is another matter. But it is certainly
> correct.

We can't know whether the complaint is correct without knowing what
the complaint is.

It could be something along the lines of

Variable "stats" may be used before being initialized

And it could be that, due to circumstances beyond lint's ability to
analyze, "stats" actually cannot ever be used before it's initialized.

I doubt that lint would complain just because a variable declaration
doesn't include an initializer. For example, lint probably wouldn't
complain about something like this:

int x;
x = 42;
printf("x = %d\n", x);

In my hypothetical scenario, the ``= 0'' is necessary to inhibit a
spurious warning from lint, and removing the ``= 0'' is necessary to
allow another tool, perhaps something like valgrind, to confirm that
the warning is in fact spurious.

An alternative might be to restructure the code so that it's obvious,
even to lint, that stats is never actually used before it's
initialized. It's possible that such restructuring would result in
clearer, simpler, and all-around better code. But without actually
looking at the code in question, it's impossible to be sure.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"