Ptr Casting syntax?? 
Author Message
 Ptr Casting syntax??

i: integer;
data := ptr;

i := integer(data^);



Sat, 01 Oct 2005 00:21:26 GMT  
 Ptr Casting syntax??

Quote:

> i: integer;
> data := ptr;

> i := integer(data^);

There is no ISO 7185 mechanisim for casting. It was not an oversight;
Pascal is supposed to be a "type secure" language, meaning that you
don't create arbitrary addresses pointing to objects. Such constructs
are easily abused.

However, this is a common extention, see your particular implementation's
documentation.

If you REALLY want to do that and stay in the standard language, there is
still a way, relying on a trap door Wirth left in the language. See:

www.moorecad.com/standardpascal

FAQ for details.

--
It amazes me that programmers feel the need to program in
the same language as others. The advantages of different
hair growing products are better established than the
advantages of any particular choice of language.



Sat, 01 Oct 2005 12:01:57 GMT  
 Ptr Casting syntax??

Quote:

> There is no ISO 7185 mechanisim for casting. It was not an oversight;
> Pascal is supposed to be a "type secure" language, meaning that you
> don't create arbitrary addresses pointing to objects. Such constructs
> are easily abused.

> However, this is a common extention, see your particular implementation's
> documentation.

> If you REALLY want to do that and stay in the standard language, there is
> still a way, relying on a trap door Wirth left in the language. See:

> www.moorecad.com/standardpascal

Is this a reference to the mis-use of variant records?
If so, Wirth may have left a trap door, but BS 6192 (ISO 7185) did not,
and compilers should not.

Mis-using variant records in an attempt to make machine-dependent type
conversions produces an undefined result, and an implementation should fail
the program. It is NOT legal ISO Pascal.
--
Bill-Findlay chez blue-yonder.co.uk ("-" => "")



Sat, 01 Oct 2005 22:03:53 GMT  
 Ptr Casting syntax??

Quote:



> > There is no ISO 7185 mechanisim for casting. It was not an oversight;
> > Pascal is supposed to be a "type secure" language, meaning that you
> > don't create arbitrary addresses pointing to objects. Such constructs
> > are easily abused.

> > However, this is a common extention, see your particular implementation's
> > documentation.

> > If you REALLY want to do that and stay in the standard language, there is
> > still a way, relying on a trap door Wirth left in the language. See:

> > www.moorecad.com/standardpascal

> Is this a reference to the mis-use of variant records?
> If so, Wirth may have left a trap door, but BS 6192 (ISO 7185) did not,
> and compilers should not.

Undiscriminated variant records are very much a part of ISO 7185. Access to variant
fields which are not active is an "error", but it is allowed to produce no
message on such an error. In fact, for the case where the tag field does not
exist, it requires extraordinary measures to detect such errors at runtime
(such as forcing a hidden tagfield to appear).

Wirth never particularly avocated the use of variant record types as type changers,
and neither do I. But the fact is that it exists, and some programs use it.

Quote:

> Mis-using variant records in an attempt to make machine-dependent type
> conversions produces an undefined result, and an implementation should fail
> the program. It is NOT legal ISO Pascal.
> --
> Bill-Findlay chez blue-yonder.co.uk ("-" => "")

--
It amazes me that programmers feel the need to program in
the same language as others. The advantages of different
hair growing products are better established than the
advantages of any particular choice of language.


Sun, 02 Oct 2005 00:12:33 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Real: Ptr Casting syntax??

2. 4DA2DE39 cmp dword ptr [edx],$00

3. ptr to string

4. ptr to array

5. Prot mode ptr need a touch?

6. Phy addr from prot mode ptr

7. type casting (objects)

8. Help with Cast in Interbase !!

9. invalid type casting question

10. Ray-Casting

11. type conversion/casting question

12. CAST in Local SQL? SQL Help needed

 

 
Powered by phpBB® Forum Software