Warning: types for unchecked conversion have different sizes 
Author Message
 Warning: types for unchecked conversion have different sizes

Hello,

This warning message is puzzling me all night. I don't get this warning
message when I compiled this line with ObjectAda 7.1.1 for Windows. This
warning message begin to flourished when I compiled using gnat-3.12p for
linux.

    function To_Char is new Ada.Unchecked_Conversion (Integer, Char);

Can anyone help to explain why is this happening?

--
Adrian BY, Hoe
--------------

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Fri, 06 Dec 2002 03:00:00 GMT  
 Warning: types for unchecked conversion have different sizes


Quote:
>Hello,

>This warning message is puzzling me all night. I don't get this warning
>message when I compiled this line with ObjectAda 7.1.1 for Windows. This
>warning message begin to flourished when I compiled using gnat-3.12p for
>linux.

>    function To_Char is new Ada.Unchecked_Conversion (Integer, Char);

>Can anyone help to explain why is this happening?

>--
>Adrian BY, Hoe
>--------------

>Sent via Deja.com http://www.deja.com/
>Before you buy.

GNAT is right to give you a warning on this one.  Integer and Char
types are different sizes on just about any platform, and Unchecked_
Conversion between them can and often will yield garbage.

Don't know why ObjectAda didn't warn you, but in general GNAT is
very conscientious about giving warnings for mistakes like this.

--
Chris Green



Fri, 06 Dec 2002 03:00:00 GMT  
 Warning: types for unchecked conversion have different sizes
Adrian Hoe:

Quote:
>     function To_Char is new Ada.Unchecked_Conversion (Integer, Char);
> Can anyone help to explain why is this happening?

Oops your function has few chances to give a correct result (Integer and Char
not the same size). The right and safe thing to use is Char'Val(...) predefined
function (attribute).
HTH
______________________________________________________
Gautier  --  http://members.xoom.com/gdemont/gsoft.htm


Fri, 06 Dec 2002 03:00:00 GMT  
 Warning: types for unchecked conversion have different sizes

Quote:

>Hello,

>This warning message is puzzling me all night. I don't get this warning
>message when I compiled this line with ObjectAda 7.1.1 for Windows. This
>warning message begin to flourished when I compiled using gnat-3.12p for
>linux.

>    function To_Char is new Ada.Unchecked_Conversion (Integer, Char);

>Can anyone help to explain why is this happening?

Because "types for unchecked conversion have different sizes"? The
size for Integer or Char or both varies between ObjectAda for Windows
for the ix86 and gnat for Linux for the ix86 (assumed; the CPU is
important here.) If this is the best way to do it, you'll probably need
to set up a new integer type, and use "for Foo'Size use n" with n the
same on both of them.

While you can bet on the obvious (Character'Size = 8; Wide_Character'Size =
16), the 'Sizes of most types, especially Integer, will vary from platform
to platform. You can't rely on being about to use Unchecked_Conversion for
them in a portable fashion.

--

http/ftp: x8b4e53cd.dhcp.okstate.edu
"A dynamic character with an ability to survive certain death and
a questionable death scene leaving no corpse? Face it, we'll never
see her again." - Sluggy {*filter*}



Fri, 06 Dec 2002 03:00:00 GMT  
 Warning: types for unchecked conversion have different sizes

Quote:

>Adrian Hoe:

>>     function To_Char is new Ada.Unchecked_Conversion (Integer, Char);

>> Can anyone help to explain why is this happening?

>Oops your function has few chances to give a correct result (Integer and Char
>not the same size).

type Char is 0 .. 2**32 - 1;

Now it is (at least on some systems). It's not like it was defined anywhere
else, so how do we know what definition he's using?

--

http/ftp: x8b4e53cd.dhcp.okstate.edu
"A dynamic character with an ability to survive certain death and
a questionable death scene leaving no corpse? Face it, we'll never
see her again." - Sluggy {*filter*}



Fri, 06 Dec 2002 03:00:00 GMT  
 Warning: types for unchecked conversion have different sizes
or even Character'Val (...)
Quote:

> Adrian Hoe:

> >     function To_Char is new Ada.Unchecked_Conversion (Integer, Char);

> > Can anyone help to explain why is this happening?

> Oops your function has few chances to give a correct result (Integer and Char
> not the same size). The right and safe thing to use is Char'Val(...) predefined
> function (attribute).
> HTH
> ______________________________________________________
> Gautier  --  http://members.xoom.com/gdemont/gsoft.htm



Sat, 07 Dec 2002 03:00:00 GMT  
 Warning: types for unchecked conversion have different sizes

Quote:



> >Hello,

> >message when I compiled this line with ObjectAda 7.1.1 for Windows.
This
> >warning message begin to flourished when I compiled using gnat-3.12p
for
> >linux.

> >    function To_Char is new Ada.Unchecked_Conversion (Integer, Char);

> >Can anyone help to explain why is this happening?

> Because "types for unchecked conversion have different sizes"? The
> size for Integer or Char or both varies between ObjectAda for Windows
> for the ix86 and gnat for Linux for the ix86 (assumed; the CPU is
> important here.) If this is the best way to do it, you'll probably
need
> to set up a new integer type, and use "for Foo'Size use n" with n the
> same on both of them.

> While you can bet on the obvious (Character'Size = 8;

Wide_Character'Size =

Quote:
> 16), the 'Sizes of most types, especially Integer, will vary from
platform
> to platform. You can't rely on being about to use Unchecked_Conversion
for
> them in a portable fashion.

> --


In my ObjectAda source, I define:

    subtype Char is Interfaces.C.Char;

The original idea is to interface to a C library function. Question: If
I were to use any other methods other than Unchecked_Conversion, can I
still main consistency to the interface to the C library function on any
other platforms?
--
Adrian BY, Hoe
--------------

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 09 Dec 2002 03:00:00 GMT  
 Warning: types for unchecked conversion have different sizes


Quote:
> The original idea is to interface to a C library function.
> Question: If I were to use any other methods other than
> Unchecked_Conversion, can I still main consistency to the
> interface to the C library function on any other platforms?

Unchecked_Conversion is neither helpful nor necessary in this
quest, it is perfectly easy to solve this problem without UC.
In practice, in all available implementations of Ada, and any
likely to appear in future on normal byte machines, Character
is the same as C char in any case, so you don't even need to
mess with Interfaces.C.

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 09 Dec 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Unchecked_Conversion on different sized types -- problem?

2. An alternative to Unchecked Conversion

3. Unchecked Conversion - Thanks for the info

4. Ada 83 - avoiding unchecked conversions.

5. : Unchecked conversion

6. : Unchecked conversion

7. Unchecked Conversion and 'Valid

8. Valid Attribute and Unchecked Conversion

9. required unchecked conversions

10. behaviour of rendez-vous after unchecked conversion (LONG)

11. unchecked conversion

12. Different window sizes in different sceen resolutions

 

 
Powered by phpBB® Forum Software