comp.lang.ada
 help / color / mirror / Atom feed
* changing alignment of built-in boolean
@ 2005-10-14 20:03 invalidemail
  2005-10-14 22:55 ` Ludovic Brenta
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: invalidemail @ 2005-10-14 20:03 UTC (permalink / raw)


Is it possible, in GNAT, to force the built-in Boolean type to use
4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
to a package that insists on 32-bit variables on 4-byte-aligned
addresses.

Feel free to suggest some other strategy for accomplishing this, though
I'd prefer not to make extensive changes to the Ada code (such as
changing it to use a subtype of Boolean).

I'm using GNAT 3.15p on HPUX.

Thanks.




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

* Re: changing alignment of built-in boolean
  2005-10-14 20:03 changing alignment of built-in boolean invalidemail
@ 2005-10-14 22:55 ` Ludovic Brenta
  2005-10-14 23:33   ` invalidemail
  2005-10-14 23:29 ` tmoran
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Ludovic Brenta @ 2005-10-14 22:55 UTC (permalink / raw)


invalidemail@aerojockey.com writes:

> Is it possible, in GNAT, to force the built-in Boolean type to use
> 4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
> to a package that insists on 32-bit variables on 4-byte-aligned
> addresses.
>
> Feel free to suggest some other strategy for accomplishing this, though
> I'd prefer not to make extensive changes to the Ada code (such as
> changing it to use a subtype of Boolean).
>
> I'm using GNAT 3.15p on HPUX.
>
> Thanks.

type T is record
   B : Boolean;
   ...
end record;

for T use record
   B at 0 range 0 .. 31;
   ...
end record;

package P is
   subtype External_Boolean is Boolean;
   for External_Boolean'Size use 32;
   for External_Boolean'Alignment use 32;

   procedure External (B : in External_Boolean);
   pragma Import (C, External, "some_function");
end P;

-- 
Ludovic Brenta.



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

* Re: changing alignment of built-in boolean
  2005-10-14 20:03 changing alignment of built-in boolean invalidemail
  2005-10-14 22:55 ` Ludovic Brenta
@ 2005-10-14 23:29 ` tmoran
  2005-10-15  1:39 ` Steve
  2005-10-15  6:40 ` Jeffrey R. Carter
  3 siblings, 0 replies; 13+ messages in thread
From: tmoran @ 2005-10-14 23:29 UTC (permalink / raw)


> Is it possible, in GNAT, to force the built-in Boolean type to use
> 4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
> to a package that insists on 32-bit variables on 4-byte-aligned
> addresses.
    So it's not really the case that *every* Boolean needs this, just the
ones in the data structures you share with that other package.  If you are
sharing records, it would be safer to *always* use a representation clause
on the shared records to make sure alignments, sizes, packing, and
ordering all match.  If you are passing simple Boolean variables or
expressions as subroutine parameters, the Convention on your pragma
Imports ought to do the right thing.



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

* Re: changing alignment of built-in boolean
  2005-10-14 22:55 ` Ludovic Brenta
@ 2005-10-14 23:33   ` invalidemail
  2005-10-15  7:13     ` Martin Krischik
  0 siblings, 1 reply; 13+ messages in thread
From: invalidemail @ 2005-10-14 23:33 UTC (permalink / raw)


Ludovic Brenta wrote:
> invalidemail@aerojockey.com writes:
>
> > Is it possible, in GNAT, to force the built-in Boolean type to use
> > 4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
> > to a package that insists on 32-bit variables on 4-byte-aligned
> > addresses.
> >
> > Feel free to suggest some other strategy for accomplishing this, though
> > I'd prefer not to make extensive changes to the Ada code (such as
> > changing it to use a subtype of Boolean).
> >
> > I'm using GNAT 3.15p on HPUX.
> >
> > Thanks.
>
> type T is record
>    B : Boolean;
>    ...
> end record;
>
> for T use record
>    B at 0 range 0 .. 31;
>    ...
> end record;
>
> package P is
>    subtype External_Boolean is Boolean;
>    for External_Boolean'Size use 32;
>    for External_Boolean'Alignment use 32;

Parenthetically, I tried this.  Compiler told me I cannot specify
attribute for subtype.

>    procedure External (B : in External_Boolean);
>    pragma Import (C, External, "some_function");
> end P;


Ok, I'm sorry.  I appear to have omitted a crucial piece of
information: this is for library level Booleans.  The Ada code
constitutes a shared library, and the program that calls the library
accesses some of the library level variables via the symbol table, but
the variables have to be 32-bits.

The record way doesn't work either, at least not without extensive
changes, because I still have to use these variables as Booleans (in
conditional expressions).

I was thinking that if there was a way to do this it would be to use
some compiler flag or an obscure, implementation-defined pragma.

Thanks anyways. :)




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

* Re: changing alignment of built-in boolean
  2005-10-14 20:03 changing alignment of built-in boolean invalidemail
  2005-10-14 22:55 ` Ludovic Brenta
  2005-10-14 23:29 ` tmoran
@ 2005-10-15  1:39 ` Steve
  2005-10-15  6:45   ` Jeffrey R. Carter
  2005-10-15  6:40 ` Jeffrey R. Carter
  3 siblings, 1 reply; 13+ messages in thread
From: Steve @ 2005-10-15  1:39 UTC (permalink / raw)


<invalidemail@aerojockey.com> wrote in message 
news:1129320236.007525.185300@g44g2000cwa.googlegroups.com...
> Is it possible, in GNAT, to force the built-in Boolean type to use
> 4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
> to a package that insists on 32-bit variables on 4-byte-aligned
> addresses.
>
> Feel free to suggest some other strategy for accomplishing this, though
> I'd prefer not to make extensive changes to the Ada code (such as
> changing it to use a subtype of Boolean).
>
> I'm using GNAT 3.15p on HPUX.
>
> Thanks.
>

GNAT appears to be happy with the following:

procedure ClaTestAlignment is
  value : Boolean;
  for value'size use 32;
  for value'alignment use 4;
begin
  null;
end ClaTestAlignment;

Also, me thinks (but cannot confirm) that the alignment value is in terms of 
storage units not bits.

Steve
(The Duck)





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

* Re: changing alignment of built-in boolean
  2005-10-14 20:03 changing alignment of built-in boolean invalidemail
                   ` (2 preceding siblings ...)
  2005-10-15  1:39 ` Steve
@ 2005-10-15  6:40 ` Jeffrey R. Carter
  2005-10-16 17:48   ` invalidemail
  2005-11-09  3:25   ` Anonymous Coward
  3 siblings, 2 replies; 13+ messages in thread
From: Jeffrey R. Carter @ 2005-10-15  6:40 UTC (permalink / raw)


invalidemail@aerojockey.com wrote:
> Is it possible, in GNAT, to force the built-in Boolean type to use
> 4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
> to a package that insists on 32-bit variables on 4-byte-aligned
> addresses.

You could always modify the compiler :)

You might want to look at user-defined boolean types here (it's sometimes a 
little confusing in Ada to distinguish between integer types and type Integer, 
character types and type Character, string types and type String, boolean types 
and type Boolean):

type Big_Boolean is new Boolean;
for Big_Boolean'Size use 32;
for Big_Boolean'Alignment use 4;

Conditions can be of any boolean type, so you can use this just like type Boolean:

B : Big_Boolean;

if B then ...

while B loop ...

exit Some_Loop when B;

-- 
Jeff Carter
"If a sperm is wasted, God gets quite irate."
Monty Python's the Meaning of Life
56



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

* Re: changing alignment of built-in boolean
  2005-10-15  1:39 ` Steve
@ 2005-10-15  6:45   ` Jeffrey R. Carter
  0 siblings, 0 replies; 13+ messages in thread
From: Jeffrey R. Carter @ 2005-10-15  6:45 UTC (permalink / raw)


Steve wrote:

> Also, me thinks (but cannot confirm) that the alignment value is in terms of 
> storage units not bits.

Sort of. See ARM 13.3. Technically, it means the address mod the alignment is zero.

-- 
Jeff Carter
"If a sperm is wasted, God gets quite irate."
Monty Python's the Meaning of Life
56



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

* Re: changing alignment of built-in boolean
  2005-10-14 23:33   ` invalidemail
@ 2005-10-15  7:13     ` Martin Krischik
  2005-10-17 18:02       ` Jean-Pierre Rosen
  0 siblings, 1 reply; 13+ messages in thread
From: Martin Krischik @ 2005-10-15  7:13 UTC (permalink / raw)


invalidemail@aerojockey.com wrote:

> Ludovic Brenta wrote:
>> invalidemail@aerojockey.com writes:
>>
>> > Is it possible, in GNAT, to force the built-in Boolean type to use
>> > 4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
>> > to a package that insists on 32-bit variables on 4-byte-aligned
>> > addresses.

>> package P is
>>    subtype External_Boolean is Boolean;
>>    for External_Boolean'Size use 32;
>>    for External_Boolean'Alignment use 32;
> 
> Parenthetically, I tried this.  Compiler told me I cannot specify
> attribute for subtype.

A typo from Ludovic. you really need:

type External_Boolean is new Boolean;
for External_Boolean'Size use 32;
for External_Boolean'Alignment use 32;

Of corse you need an explicit convertion between Boolean and
External_Boolean. 

> Ok, I'm sorry.  I appear to have omitted a crucial piece of
> information: this is for library level Booleans.  The Ada code
> constitutes a shared library, and the program that calls the library
> accesses some of the library level variables via the symbol table, but
> the variables have to be 32-bits.

External_Boolean will work fine for that.

> The record way doesn't work either, at least not without extensive
> changes, because I still have to use these variables as Booleans (in
> conditional expressions).

> I was thinking that if there was a way to do this it would be to use
> some compiler flag or an obscure, implementation-defined pragma.
> 
> Thanks anyways. :)

Martin

-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

* Re: changing alignment of built-in boolean
  2005-10-15  6:40 ` Jeffrey R. Carter
@ 2005-10-16 17:48   ` invalidemail
  2005-11-09  3:25   ` Anonymous Coward
  1 sibling, 0 replies; 13+ messages in thread
From: invalidemail @ 2005-10-16 17:48 UTC (permalink / raw)



Jeffrey R. Carter wrote:
> invalidemail@aerojockey.com wrote:
> > Is it possible, in GNAT, to force the built-in Boolean type to use
> > 4-byte (32-bit) alignment?  Reason: I have to interface some Ada code
> > to a package that insists on 32-bit variables on 4-byte-aligned
> > addresses.
>
> You could always modify the compiler :)
>
> You might want to look at user-defined boolean types here (it's sometimes a
> little confusing in Ada to distinguish between integer types and type Integer,
> character types and type Character, string types and type String, boolean types
> and type Boolean):
>
> type Big_Boolean is new Boolean;
> for Big_Boolean'Size use 32;
> for Big_Boolean'Alignment use 4;
>
> Conditions can be of any boolean type, so you can use this just like type Boolean:

Yes, but there appears to be one little catch:

   if B and then (Some_Integer /= 0) then ...

Unfortunately I got stuff like this all over the Ada code :(  Otherwise
this would be something I could do with a simple search and replace.
Maybe there's a flag to loosen the type checking for this case.
Probably not.  Oh well.

Thanks.




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

* Re: changing alignment of built-in boolean
  2005-10-15  7:13     ` Martin Krischik
@ 2005-10-17 18:02       ` Jean-Pierre Rosen
  0 siblings, 0 replies; 13+ messages in thread
From: Jean-Pierre Rosen @ 2005-10-17 18:02 UTC (permalink / raw)


Martin Krischik a �crit :

> A typo from Ludovic. you really need:
> 
> type External_Boolean is new Boolean;
> for External_Boolean'Size use 32;
> for External_Boolean'Alignment use 32;
> 
> Of corse you need an explicit convertion between Boolean and
> External_Boolean. 
> 
Not always. For example, an if statement will accept a condition whose 
type is External_Boolean (5.3(4): A condition is expected to be of any 
boolean type, and 3.5.3(1): Any descendant of the predefined type 
Boolean is called a boolean type. )
-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: changing alignment of built-in boolean
  2005-10-15  6:40 ` Jeffrey R. Carter
  2005-10-16 17:48   ` invalidemail
@ 2005-11-09  3:25   ` Anonymous Coward
  2005-11-09  5:42     ` christoph.grein
  2005-11-09 22:14     ` Jeffrey R. Carter
  1 sibling, 2 replies; 13+ messages in thread
From: Anonymous Coward @ 2005-11-09  3:25 UTC (permalink / raw)


In article <Nv14f.1603$hY6.1538@newsread1.news.pas.earthlink.net>, Jeffrey R. Carter wrote:
> 
> You might want to look at user-defined boolean types here (it's
> sometimes a little confusing in Ada to distinguish between integer
> types and type Integer, character types and type Character, string
> types and type String, boolean types and type Boolean):
> 
> type Big_Boolean is new Boolean;
> for Big_Boolean'Size use 32;
> for Big_Boolean'Alignment use 4;
> 
> Conditions can be of any boolean type, so you can use this just like
> type Boolean:
> 
> B : Big_Boolean;
> 
> if B then ...
> 
> while B loop ...
> 
> exit Some_Loop when B;

I tried this, and where I had problems was trying to assign the result
of a boolean expression to Big_Boolean.  ie. Compiling:

   procedure Big_Boolean_Experiment is

      type Big_Boolean_Type is new Boolean;

      --The following line is probably useless on booleans:
      pragma Convention (Convention => C,
                         Entity     => Big_Boolean_Type);

      for Big_Boolean_Type'Size use 32;

      Big_Boolean    : Big_Boolean_Type;
      Native_Boolean : Boolean;

   begin

      Big_Boolean    := 2=2; --gnat rejects this line
      Native_Boolean := 2=2;

   end Big_Boolean_Experiment;

results in this error from gnat:

   $ gcc -c -gnatR3 big_boolean_experiment.adb
   big_boolean_experiment.adb:14:23: expected type "Big_Boolean_Type" defined at line 3
   big_boolean_experiment.adb:14:23: found type "Standard.Boolean"

   $ gcc --version
   gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)



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

* Re: changing alignment of built-in boolean
  2005-11-09  3:25   ` Anonymous Coward
@ 2005-11-09  5:42     ` christoph.grein
  2005-11-09 22:14     ` Jeffrey R. Carter
  1 sibling, 0 replies; 13+ messages in thread
From: christoph.grein @ 2005-11-09  5:42 UTC (permalink / raw)


Big_Boolean    := 2=2; --gnat rejects

Of course because "=" returns a Boolean, not a Big_Boolean_Type




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

* Re: changing alignment of built-in boolean
  2005-11-09  3:25   ` Anonymous Coward
  2005-11-09  5:42     ` christoph.grein
@ 2005-11-09 22:14     ` Jeffrey R. Carter
  1 sibling, 0 replies; 13+ messages in thread
From: Jeffrey R. Carter @ 2005-11-09 22:14 UTC (permalink / raw)


Anonymous Coward wrote:
>       type Big_Boolean_Type is new Boolean;
> 
>       Big_Boolean    : Big_Boolean_Type;
> 
>       Big_Boolean    := 2=2; --gnat rejects this line
> 
>    big_boolean_experiment.adb:14:23: expected type "Big_Boolean_Type" defined at line 3
>    big_boolean_experiment.adb:14:23: found type "Standard.Boolean"

Right. The only "=" returns Boolean, so you'd need to convert it:

Big_Boolean := Big_Boolean_Type (2 = 2);

-- 
Jeff Carter
"To Err is human, to really screw up, you need C++!"
St�phane Richard
63



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

end of thread, other threads:[~2005-11-09 22:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-14 20:03 changing alignment of built-in boolean invalidemail
2005-10-14 22:55 ` Ludovic Brenta
2005-10-14 23:33   ` invalidemail
2005-10-15  7:13     ` Martin Krischik
2005-10-17 18:02       ` Jean-Pierre Rosen
2005-10-14 23:29 ` tmoran
2005-10-15  1:39 ` Steve
2005-10-15  6:45   ` Jeffrey R. Carter
2005-10-15  6:40 ` Jeffrey R. Carter
2005-10-16 17:48   ` invalidemail
2005-11-09  3:25   ` Anonymous Coward
2005-11-09  5:42     ` christoph.grein
2005-11-09 22:14     ` Jeffrey R. Carter

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