Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #348141

Re: How could defining a variable, and not using it, be a problem ?

From owl <owl@rooftop.invalid>
Newsgroups comp.os.linux.advocacy
Subject Re: How could defining a variable, and not using it, be a problem ?
Date 2016-03-30 16:26 +0000
Organization O.W.L.
Message-ID <ghjd023r.ajji@rooftop.invalid> (permalink)
References (10 earlier) <ndeim0$f4m$1@dont-email.me> <ndemuc$ln$1@dont-email.me> <ndf2iv$e4b$3@dont-email.me> <ghjdie93.ar54@rooftop.invalid> <ndgp1r$gu6$2@dont-email.me>

Show all headers | View raw


DFS <nospam@dfs.com> wrote:
> On 3/29/2016 8:42 PM, owl wrote:
>> DFS <nospam@dfs.com> wrote:
>>> On 03/29/2016 04:04 PM, Peter Köhlmann wrote:
>> ...
>>>
>>>> And you completely ignore that it is basically impossible to
>>>> determine correctness of the code by testing,
>>>
>>> Depends on the complexity of the program.
>>>
>>
>> One of the programs below had a compile-time warning.  Which one
>> doesn't appear to be working properly?
>>
>> anon@lowtide:~/code$ ./warn1 x: 7 y: 4 sum: 11 anon@lowtide:~/code$
>> ./warn2 x: 7 y: 8 sum: 15 anon@lowtide:~/code$
> 
> 
> They both appear to be working properly, but one iteration isn't a
> sufficient test.

There is only one iteration in this code.

>  To test your code for ALL possible situations
> (assuming it's intended to only sum numbers x and y):
> 
> for x = min size of x to max size of x
>  for y = min size of y to max size of y
>   if warn1(x,y) <> (x + y) then
>    print "warn1 failed at: x " & x & ", y " & y
>   endif
>   if warn2(x,y) <> (x + y)
>    print "warn2 failed at: x " & x & ", y " & y
>   endif
>  next y
> next x
> 
> What was the compiler warning?
> 

anon@lowtide:~$ cd code
anon@lowtide:~/code$ gcc -Wall -o warn1 warn1.c
anon@lowtide:~/code$ gcc -Wall -o warn2 warn2.c
warn2.c: In function ‘blah’:
warn2.c:19:6: warning: unused variable ‘x’ [-Wunused-variable]
  int x=4;
      ^
anon@lowtide:~/code$

> Some compiler warnings - such as 'unused variable declared' - can't
> impact the functionality,

And yet this unused variable warning did have an impact on functionality.

> and can't ever be discovered during testing
> (no whining about "out of memory!" because an unused variable was
> declared).  So it's a fact that some compiler warnings can be irrelevant
> and safely ignored.
> 

The warning above was generated because of this commented-out code:

void blah(void)
{
 int x=4;
/* y=x; */
}

Otherwise the programs are identical.

The variables x and y that are printed are at file scope.  The compiler
warns about the local-scope x in function blah() not being used.  This
results in the program generating a completely different output, because
the file-scope y never gets reassigned to the value of the local-scope
x.  What if this wrong answer resulted in nukes being launched?  The
world could then be destroyed because you ignored an "unused variable"
warning.

Back to comp.os.linux.advocacy | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

I like taking cock up my ass "7" <idiot@enemygadgets.com> - 2016-03-27 01:51 +0100
  Re: I like taking cock up my ass Fabian Russell <fb@zen.info> - 2016-03-27 15:31 +0000
    Re: I like taking cock up my ass Takuya Saitoh <taka0038@gmail.com> - 2016-03-27 09:01 -0700
      Eternal-September  Motzarella  Aioe  Dizum  Albasani Jeff-Relf.Me <@.> - 2016-03-27 09:21 -0700
        Re: Eternal-September  Motzarella  Aioe  Dizum  Albasani Nobody <nobody@nowhere.net> - 2016-03-27 12:25 -0400
        Re: Eternal-September Motzarella Aioe Dizum Albasani DFS <nospam@dfs.com> - 2016-03-27 12:31 -0400
          Re: Eternal-September Motzarella Aioe Dizum Albasani Nobody <nobody@nowhere.net> - 2016-03-27 12:39 -0400
          Eternal-September Motzarella Aioe Dizum Albasani Jeff-Relf.Me <@.> - 2016-03-27 09:51 -0700
            Re: Eternal-September Motzarella Aioe Dizum Albasani DFS <nospam@dfs.com> - 2016-03-27 13:04 -0400
              Usenet, eMail, CraigsList, WikiPedia, etc. allow <PRE>. Jeff-Relf.Me <@.> - 2016-03-27 10:13 -0700
                Re: Usenet, eMail, CraigsList, WikiPedia, etc. allow <PRE>. vallor <vallor@cultnix.org> - 2016-03-27 18:50 +0000
                Re: Usenet, eMail, CraigsList, WikiPedia, etc. allow <PRE>. benj <none@gmail.com> - 2016-03-28 00:55 -0400
                Re: Usenet, eMail, CraigsList, WikiPedia, etc. allow <PRE>. jimp@specsol.spam.sux.com - 2016-03-28 05:57 +0000
        Re: Eternal-September  Motzarella  Aioe  Dizum  Albasani tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2016-03-27 19:53 -0400
          Re: Eternal-September  Motzarella  Aioe  Dizum  Albasani chrisv <chrisv@nospam.invalid> - 2016-03-28 07:23 -0500
        Re: Eternal-September  Motzarella  Aioe  Dizum  Albasani Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-28 01:59 +0200
          Re: Eternal-September  Motzarella  Aioe  Dizum  Albasani chrisv <chrisv@nospam.invalid> - 2016-03-28 07:44 -0500
            My code only does what _I_ want, not what "you" want. Jeff-Relf.Me <@.> - 2016-03-28 06:15 -0700
            My code only does what _I_ want, not what "you" want. Jeff-Relf.Me <@.> - 2016-03-28 06:17 -0700
              Re: My code only does what _I_ want, not what "you" want. owl <owl@rooftop.invalid> - 2016-03-28 19:33 +0000
              Re: My code only does what _I_ want, not what "you" want. Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-28 23:41 +0200
                How could defining a variable, and not using it, be a problem ? Jeff-Relf.Me <@.> - 2016-03-28 14:52 -0700
                Re: How could defining a variable, and not using it, be a problem ? Somebody <somebody@nowhere.net> - 2016-03-28 18:01 -0400
                Re: How could defining a variable, and not using it, be a problem ? Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-29 00:25 +0200
                Re: How could defining a variable, and not using it, be a problem ? Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-03-28 18:30 -0400
                Re: How could defining a variable, and not using it, be a problem ? Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-29 00:50 +0200
                Re: How could defining a variable, and not using it, be a problem ? Somebody <somebody@nowhere.net> - 2016-03-28 18:54 -0400
                Re: How could defining a variable, and not using it, be a problem ? Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-03-28 21:11 -0400
                Re: How could defining a variable, and not using it, be a problem ? Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-29 15:38 +0200
                Re: How could defining a variable, and not using it, be a problem ? DFS <nospam@dfs.com> - 2016-03-29 10:09 -0400
                Re: How could defining a variable, and not using it, be a problem ? Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-29 19:54 +0200
                Re: How could defining a variable, and not using it, be a problem ? DFS <nospam@dfs.com> - 2016-03-29 14:51 -0400
                Re: How could defining a variable, and not using it, be a problem ? Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-29 22:04 +0200
                Re: How could defining a variable, and not using it, be a problem ? owl <owl@rooftop.invalid> - 2016-03-29 20:30 +0000
                Re: How could defining a variable, and not using it, be a problem ? Snit <usenet@gallopinginsanity.com> - 2016-03-29 13:59 -0700
                Re: How could defining a variable, and not using it, be a problem ? Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-29 23:57 +0200
                Re: How could defining a variable, and not using it, be a problem ? Snit <usenet@gallopinginsanity.com> - 2016-03-29 18:23 -0700
                Re: How could defining a variable, and not using it, be a problem ? chrisv <chrisv@nospam.invalid> - 2016-03-29 16:50 -0500
                Re: How could defining a variable, and not using it, be a problem ? DFS <nospam@dfs.com> - 2016-03-29 19:23 -0400
                Re: How could defining a variable, and not using it, be a problem ? owl <owl@rooftop.invalid> - 2016-03-30 00:42 +0000
                Re: How could defining a variable, and not using it, be a problem ? DFS <nospam@dfs.com> - 2016-03-30 10:52 -0400
                Re: How could defining a variable, and not using it, be a problem ? owl <owl@rooftop.invalid> - 2016-03-30 16:26 +0000
                Re: How could defining a variable, and not using it, be a problem ? Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-03-29 20:38 -0400
                Re: How could defining a variable, and not using it, be a problem ? chrisv <chrisv@nospam.invalid> - 2016-03-30 06:59 -0500
                Re: How could defining a variable, and not using it, be a problem ? Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-03-30 11:46 -0400
                Re: How could defining a variable, and not using it, be a problem ? DFS <nospam@dfs.com> - 2016-03-30 11:53 -0400
                Re: How could defining a variable, and not using it, be a problem ? Snit <usenet@gallopinginsanity.com> - 2016-03-29 12:05 -0700
                Re: How could defining a variable, and not using it, be a problem ? Snit <usenet@gallopinginsanity.com> - 2016-03-29 12:06 -0700
                Re: How could defining a variable, and not using it, be a problem ? Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-03-28 21:10 -0400
                Re: How could defining a variable, and not using it, be a problem ? DFS <nospam@dfs.com> - 2016-03-30 14:13 -0400
                Peter Kohlmann has brain damage, I think. Jeff-Relf.Me <@.> - 2016-03-28 15:53 -0700
                Re: Peter Kohlmann has brain damage, I think. owl <owl@rooftop.invalid> - 2016-03-28 23:32 +0000
                Re: My code only does what _I_ want, not what "you" want. chrisv <chrisv@nospam.invalid> - 2016-03-29 07:24 -0500
            Re: Eternal-September Motzarella Aioe Dizum Albasani DFS <nospam@dfs.com> - 2016-03-29 10:21 -0400
              Re: Eternal-September Motzarella Aioe Dizum Albasani Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-03-29 19:50 +0200
                Re: Eternal-September Motzarella Aioe Dizum Albasani chrisv <chrisv@nospam.invalid> - 2016-03-29 13:12 -0500
                *Spank*  Dumfsck and Kreep chrisv <chrisv@nospam.invalid> - 2016-03-29 14:29 -0500
                Re: *Spank*  Dumfsck and Kreep owl <owl@rooftop.invalid> - 2016-03-29 19:36 +0000
                Re: *Spank* Dumfsck and Kreep DFS <nospam@dfs.com> - 2016-03-29 15:42 -0400
                Re: Eternal-September Motzarella Aioe Dizum Albasani DFS <nospam@dfs.com> - 2016-03-29 15:59 -0400
                Re: Eternal-September Motzarella Aioe Dizum Albasani DFS <nospam@dfs.com> - 2016-03-30 10:51 -0400
    Re: I like taking cock up my ass "Delgato" <delgato@gmail.com> - 2016-04-02 03:01 +0200

csiph-web