comp.lang.ada
 help / color / mirror / Atom feed
* X := X; Compiler Warning?
@ 2010-04-12 14:40 Warren
  2010-04-12 16:27 ` John B. Matthews
  0 siblings, 1 reply; 3+ messages in thread
From: Warren @ 2010-04-12 14:40 UTC (permalink / raw)


This weekend, I discovered a problem after some
effort in debugging. The culprit was something
stupid like this:

  Position_X : Line_Index := ...
begin

  loop
    ..
    Position_X := Position_X;  -- whoops
    ..
    exit when ...;
  end loop;

Obviously, that should have been coded as:

    Position_X := Position_X + 1;

As outlined here, it is trivial to spot. 

But with the longer variable names (in the original
code), I somehow missed it in amongst all of the
other statements.

Now isn't this something that is normally reported
as a warning?  I'm using gnat, so perhaps I need an
additional compiler option.

Thanks, Warren



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: X := X; Compiler Warning?
  2010-04-12 14:40 X := X; Compiler Warning? Warren
@ 2010-04-12 16:27 ` John B. Matthews
  2010-04-12 17:39   ` Warren
  0 siblings, 1 reply; 3+ messages in thread
From: John B. Matthews @ 2010-04-12 16:27 UTC (permalink / raw)


In article <Xns9D586C840409EWarrensBlatherings@188.40.43.213>,
 Warren <ve3wwg@gmail.com> wrote:

> This weekend, I discovered a problem after some
> effort in debugging. The culprit was something
> stupid like this:
> 
>   Position_X : Line_Index := ...
> begin
> 
>   loop
>     ..
>     Position_X := Position_X;  -- whoops
>     ..
>     exit when ...;
>   end loop;
> 
> Obviously, that should have been coded as:
> 
>     Position_X := Position_X + 1;
> 
> As outlined here, it is trivial to spot. 
> 
> But with the longer variable names (in the original
> code), I somehow missed it in amongst all of the
> other statements.
> 
> Now isn't this something that is normally reported
> as a warning?  I'm using gnat, so perhaps I need an
> additional compiler option.

Add "-gnatwXX" to your "-cargs" in gnatmake, where XX is among these

<http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gnat_ugn_unw/
Warning-Message-Control.html#Warning-Message-Control>

For example, -gnatwr yields

warning: useless assignment of "Position_X" to itself

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: X := X; Compiler Warning?
  2010-04-12 16:27 ` John B. Matthews
@ 2010-04-12 17:39   ` Warren
  0 siblings, 0 replies; 3+ messages in thread
From: Warren @ 2010-04-12 17:39 UTC (permalink / raw)


John B. Matthews expounded in news:nospam-EBAEFB.12273312042010
@news.aioe.org:

> In article <Xns9D586C840409EWarrensBlatherings@188.40.43.213>,
>  Warren <ve3wwg@gmail.com> wrote:

>> Obviously, that should have been coded as:
>> 
>>     Position_X := Position_X + 1;

> Add "-gnatwXX" to your "-cargs" in gnatmake, where XX is among these
> 
> <http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gnat_ugn_unw/
> Warning-Message-Control.html#Warning-Message-Control>
> 
> For example, -gnatwr yields
> 
> warning: useless assignment of "Position_X" to itself

Excellent, thanks.

Warren



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-12 17:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-12 14:40 X := X; Compiler Warning? Warren
2010-04-12 16:27 ` John B. Matthews
2010-04-12 17:39   ` Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox