comp.lang.ada
 help / color / mirror / Atom feed
* Avoiding warnings
@ 2006-02-20 10:05 ada_wannabe
  2006-02-20 13:51 ` Justin Gombos
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: ada_wannabe @ 2006-02-20 10:05 UTC (permalink / raw)


Hello everybody. Suppose we have the next code that converts data types
between different architectures:

procedure p1(..)
begin
...
if Standard'Default_Bit_Order=1 then
...
else
...
end p1;

When I compile the source, the GNAT compiler gives me the next warning:

warning: condition is always True

How can I avoid this warning?




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

* Re: Avoiding warnings
  2006-02-20 10:05 Avoiding warnings ada_wannabe
@ 2006-02-20 13:51 ` Justin Gombos
  2006-02-21 21:32 ` Simon Wright
  2006-02-22 22:45 ` Stephen Leake
  2 siblings, 0 replies; 6+ messages in thread
From: Justin Gombos @ 2006-02-20 13:51 UTC (permalink / raw)


> When I compile the source, the GNAT compiler gives me the next warning:
> 
> warning: condition is always True
> 
> How can I avoid this warning?

GNAT has a non-Ada pragma to turn warnings off.  I believe you would
code it like this:

> procedure p1(..)
> begin
> ...

pragma Warnings(off);

> if Standard'Default_Bit_Order=1 then

pragma Warnings(on);

> ...
> else
> ...
> end p1;



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

* Re: Avoiding warnings
  2006-02-20 10:05 Avoiding warnings ada_wannabe
  2006-02-20 13:51 ` Justin Gombos
@ 2006-02-21 21:32 ` Simon Wright
  2006-02-22 22:45 ` Stephen Leake
  2 siblings, 0 replies; 6+ messages in thread
From: Simon Wright @ 2006-02-21 21:32 UTC (permalink / raw)


"ada_wannabe" <luis.sainz@gmail.com> writes:

> Hello everybody. Suppose we have the next code that converts data types
> between different architectures:
>
> procedure p1(..)
> begin
> ...
> if Standard'Default_Bit_Order=1 then

Standard'Default_Bit_Order is a GNAT special, your code would be more
portable (and readable) if you used System.Default_Bit_Order.



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

* Re: Avoiding warnings
  2006-02-20 10:05 Avoiding warnings ada_wannabe
  2006-02-20 13:51 ` Justin Gombos
  2006-02-21 21:32 ` Simon Wright
@ 2006-02-22 22:45 ` Stephen Leake
  2006-02-23 20:05   ` Simon Wright
  2006-03-04  1:25   ` Brian.Gaffney
  2 siblings, 2 replies; 6+ messages in thread
From: Stephen Leake @ 2006-02-22 22:45 UTC (permalink / raw)


"ada_wannabe" <luis.sainz@gmail.com> writes:

> Hello everybody. Suppose we have the next code that converts data types
> between different architectures:
>
> procedure p1(..)
> begin
> ...
> if Standard'Default_Bit_Order=1 then
> ...
> else
> ...
> end p1;
>
> When I compile the source, the GNAT compiler gives me the next warning:
>
> warning: condition is always True
>
> How can I avoid this warning?

Others have shown you how to avoid the warning, but they have not
pointed out that the warning is still correct; the 'else' clause of
this 'if' statement will _never_ be executed.

If you want to write code that converts record layouts between
machines of different endianness, you need something different.

See SAL.Endianness for one way to do it.
http://www.toadmail.com/~ada_wizard/ada/sal.html 

See Ada Letters September 2005, article by Randal Andress for an
extension of this technique.

See http://www.ada-auth.org/ai-files/grab_bag/bitorder.pdf for the
_right_ way to do it. Unfortunately, GNAT does not implement this. If
you care about that, send them an email asking them to implement
AI95-00133. If they get enough such emails, they will eventually
implement it :).

-- 
-- Stephe



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

* Re: Avoiding warnings
  2006-02-22 22:45 ` Stephen Leake
@ 2006-02-23 20:05   ` Simon Wright
  2006-03-04  1:25   ` Brian.Gaffney
  1 sibling, 0 replies; 6+ messages in thread
From: Simon Wright @ 2006-02-23 20:05 UTC (permalink / raw)


Stephen Leake <stephe_on_the_web@toadmail.com> writes:

> "ada_wannabe" <luis.sainz@gmail.com> writes:
>
>> Hello everybody. Suppose we have the next code that converts data types
>> between different architectures:
>>
>> procedure p1(..)
>> begin
>> ...
>> if Standard'Default_Bit_Order=1 then
>> ...
>> else
>> ...
>> end p1;
>>
>> When I compile the source, the GNAT compiler gives me the next warning:
>>
>> warning: condition is always True
>>
>> How can I avoid this warning?
>
> Others have shown you how to avoid the warning, but they have not
> pointed out that the warning is still correct; the 'else' clause of
> this 'if' statement will _never_ be executed.

Unless of course OP had been running on a Power Mac or a SPARC or
... where "condition is always False"!



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

* Re: Avoiding warnings
  2006-02-22 22:45 ` Stephen Leake
  2006-02-23 20:05   ` Simon Wright
@ 2006-03-04  1:25   ` Brian.Gaffney
  1 sibling, 0 replies; 6+ messages in thread
From: Brian.Gaffney @ 2006-03-04  1:25 UTC (permalink / raw)


Stephen Leake wrote:
> See http://www.ada-auth.org/ai-files/grab_bag/bitorder.pdf for the
> _right_ way to do it. Unfortunately, GNAT does not implement this. If
> you care about that, send them an email asking them to implement
> AI95-00133. If they get enough such emails, they will eventually
> implement it :).

Or you could ask them to implement Ada'0y, since this proposal looks
like the basis for the draft RM.  The GNAT RM justification for the
current implementation uses text from the Ada'95 RM, which is changed
in the '0y.

(I need to look into this more, but I think this would solve a problem
we are having trying to unit test on an opposite-endian host.)

          --Bg
          --Chip away the stone, Sissaphis, chip away the stone.
          --Make the burden lighter if you must roll that rock alone.




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

end of thread, other threads:[~2006-03-04  1:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-20 10:05 Avoiding warnings ada_wannabe
2006-02-20 13:51 ` Justin Gombos
2006-02-21 21:32 ` Simon Wright
2006-02-22 22:45 ` Stephen Leake
2006-02-23 20:05   ` Simon Wright
2006-03-04  1:25   ` Brian.Gaffney

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