comp.lang.ada
 help / color / mirror / Atom feed
* [Q] pragma Warnings
@ 2007-11-28 18:53 Georg Bauhaus
  2007-11-28 19:56 ` Robert A Duff
  2007-11-29 22:37 ` Stephen Leake
  0 siblings, 2 replies; 4+ messages in thread
From: Georg Bauhaus @ 2007-11-28 18:53 UTC (permalink / raw)


In http://www.adacore.com/2007/11/19/ada-gem-18/
Bob Duff explains how to use GNAT's pragma Warnings.

The effect is that GNAT users can control individual
warnings by placing suitably crafted pragmas in
source code, next to the lines that trigger the warning.

Another effect is that some Ada programs are used with
two or more targets and are translated using two or more
different compilers. In this case, the non-GNAT compiler
might complain about a non-supported pragma Warnings.
Placing the pragmas in the source will then defeat
the pragma's purpose because the compiler will issue
a warning about an unknown Warnings pragma. (Hopefully,
the other compiler will not report an error message,
as is predictably the case with link library pragmas.)

Is there an alternative to placing compiler specific
pragma Warnings in portable (pragma-wise) Ada programs?

(E.g., using the pragma as a configuration pragma,
in a connected region of source code but not right in it?
Using a smart IDE's filtering capabilities?)





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

* Re: [Q] pragma Warnings
  2007-11-28 18:53 [Q] pragma Warnings Georg Bauhaus
@ 2007-11-28 19:56 ` Robert A Duff
  2007-11-28 21:24   ` Georg Bauhaus
  2007-11-29 22:37 ` Stephen Leake
  1 sibling, 1 reply; 4+ messages in thread
From: Robert A Duff @ 2007-11-28 19:56 UTC (permalink / raw)


Georg Bauhaus <rm.tsoh+bauhaus@maps.futureapps.de> writes:

> In http://www.adacore.com/2007/11/19/ada-gem-18/
> Bob Duff explains how to use GNAT's pragma Warnings.

Thanks for advertising my "gem".  :-)

It's not the most interesting gem, IMHO.

> The effect is that GNAT users can control individual
> warnings by placing suitably crafted pragmas in
> source code, next to the lines that trigger the warning.
>
> Another effect is that some Ada programs are used with
> two or more targets and are translated using two or more
> different compilers. In this case, the non-GNAT compiler
> might complain about a non-supported pragma Warnings.
> Placing the pragmas in the source will then defeat
> the pragma's purpose because the compiler will issue
> a warning about an unknown Warnings pragma. (Hopefully,
> the other compiler will not report an error message,
> as is predictably the case with link library pragmas.)

Compilers are supposed to accept programs with unrecognized pragmas, and
generate runnable code.  They are also supposed to warn about
unrecognized pragmas, but there is normally a switch to turn that off.

I've developed Ada code using multiple Ada compilers at the same time.
You're right -- different Ada compilers give different warnings.
Here's what I suggest: pick one of the compilers that gives
the warnings you like, and take those ones seriously.
For the other Ada compiler(s), turn off all warnings
with a switch, or simply don't pay any attention to them
(including the warnings about pragma Warnings, if any!).

If you distribute source code, you should document your policy, so users
understand whether or not a warning is an indication that something is
wrong.

> Is there an alternative to placing compiler specific
> pragma Warnings in portable (pragma-wise) Ada programs?
>
> (E.g., using the pragma as a configuration pragma,
> in a connected region of source code but not right in it?
> Using a smart IDE's filtering capabilities?)

In GNAT, you can use pragma Warnings as a configuration pragma, but not
for specific warnings on specific lines.  E.g. you can disable all
warnings about uninitialized variables, but you can't disable a warning
on a particular variable using a config pragma.

- Bob



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

* Re: [Q] pragma Warnings
  2007-11-28 19:56 ` Robert A Duff
@ 2007-11-28 21:24   ` Georg Bauhaus
  0 siblings, 0 replies; 4+ messages in thread
From: Georg Bauhaus @ 2007-11-28 21:24 UTC (permalink / raw)



On Wed, 2007-11-28 at 14:56 -0500, Robert A Duff wrote:

> I've developed Ada code using multiple Ada compilers at the same time.
> You're right -- different Ada compilers give different warnings.
> Here's what I suggest: pick one of the compilers that gives
> the warnings you like, and take those ones seriously.
> For the other Ada compiler(s), turn off all warnings
> with a switch, or simply don't pay any attention to them
> (including the warnings about pragma Warnings, if any!).
> 
> If you distribute source code, you should document your policy, so users
> understand whether or not a warning is an indication that something is
> wrong.

A new twist on pragmatic programming. :-)
http://m-w.com/dictionary/pragmatism





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

* Re: [Q] pragma Warnings
  2007-11-28 18:53 [Q] pragma Warnings Georg Bauhaus
  2007-11-28 19:56 ` Robert A Duff
@ 2007-11-29 22:37 ` Stephen Leake
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2007-11-29 22:37 UTC (permalink / raw)


Georg Bauhaus <rm.tsoh+bauhaus@maps.futureapps.de> writes:

> Is there an alternative to placing compiler specific
> pragma Warnings in portable (pragma-wise) Ada programs?

With GNAT project files, it is easy to specify different command-line
options for different source files.

There are command line options to disable specific warnings.

So you can disable warnings at the file level (not the line level).

For non-GNAT compilers, it may be more difficult to specify different
command-line options for different files. Gnu make can do it, but it
is a pain.

-- 
-- Stephe



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

end of thread, other threads:[~2007-11-29 22:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-28 18:53 [Q] pragma Warnings Georg Bauhaus
2007-11-28 19:56 ` Robert A Duff
2007-11-28 21:24   ` Georg Bauhaus
2007-11-29 22:37 ` Stephen Leake

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