Borland Pascal 7.0 Bug 
Author Message
 Borland Pascal 7.0 Bug

Hi!

I've encountered quite an awkward bug when writing linked lists with
BP 7.0 OOP. When you're using the macro Inc with pointers, it will
do the increment incorrectly.

Inc(SomePtr, SizeOf(SomePtrType));

In this context SomePtr is a pointer-to-object, and SomePtrType is the
pointer type used to declare SomePtr. When the increment is executed,
SomePtr will not be advanced by four (as it should be) but 64(!!!) bytes.
I suspect that the compiler inserts an erroneous SHL in the binary
code generated.
Anyone who encountered the same problem?

Olaf Martens

To be mistaken is humane - but for real chaos you need a computer!



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug


|> > I've encountered quite an awkward bug when writing linked lists with
|> > BP 7.0 OOP. When you're using the macro Inc with pointers, it will
|> > do the increment incorrectly.
|> >
|> > Inc(SomePtr, SizeOf(SomePtrType));
|> >
|> > In this context SomePtr is a pointer-to-object, and SomePtrType is the
|> > pointer type used to declare SomePtr. When the increment is executed,
|> > SomePtr will not be advanced by four (as it should be) but 64(!!!)
|> > bytes. I suspect that the compiler inserts an erroneous SHL in the
|> > binary code generated.

What happen is that BP increments a pointer by the size of the data type it
points to. It can be really handy to work with pointers to array cells.

So, if this is what you are doing, I guess that Inc(SomePtr) could be enough.

Hope this helps

Jean-Marc
--
-------------------------------------------------
Jean-Marc Lasgouttes, Projet MEVAL, INRIA, France



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug
: Hi!
:
: I've encountered quite an awkward bug when writing linked lists with
: BP 7.0 OOP. When you're using the macro Inc with pointers, it will
: do the increment incorrectly.
:
: Inc(SomePtr, SizeOf(SomePtrType));
Why on earth do such a thing?

:
: In this context SomePtr is a pointer-to-object, and SomePtrType is the
: pointer type used to declare SomePtr. When the increment is executed,
: SomePtr will not be advanced by four (as it should be) but 64(!!!) bytes.
: I suspect that the compiler inserts an erroneous SHL in the binary
: code generated.
: Anyone who encountered the same problem?
The size of increment in bytes must be a square number, since you are
incrementing the pointer in SizeOf(PType) records of SizeOf(PType),
though 4 is 2 squared, while 64 is 8 squared.
Since you were using OOP, maybe if you specify the structure of the
oject, we will be able to check its size. (Did you try SizeOf?)

--
Schop, Nicked after Arthur Schopenhauer. Snail&Voice: Confidential.        |

Web: http://www.eskimo.com/~schop Anonymous FTP: ftp.eskimo.com:/u/s/schop |
UltiNet: 97:200/261 FidoNet: 2:406/119 DisasterNet: 206:9721/204           |
PowerNet: 23:606/6                                                         |
Interests: Philosophy, Music, Vegeterian cooking, Programming, Sleeping.   |
--------------- Save the planet - kill yourself! --------------------------+



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug
:
: Olaf,
:
: I wouldn't call this a bug. You are treating a pointer as a longint,
: which will give you a lot of problems. To do arithmetic on a pointer you
: have to convert it to a longint, do the arithmetic and convert it back
: to a pointer with the function Ptr.
:
: You could do something like the following:
:
:     OS = RECORD
:       O, S : WORD;
:     END;
:
:     longvalue = (LONGINT(OS(SomePtr).S) SHL 4) + OS(SomePtr).O;
:     Inc(longvalue, SizeOf(SomePtrType));
:     SomePtr := Ptr(WORD(longvalue SHR 4), WORD(Longvalue AND $F));
:
: Mind you, this is off the cuff; there could be better (shorter)
: solutions.
:
: Regards,
:
:         Dirk
Nice trick, but I am afraid it will do only for Real Mode.

--
Schop, Nicked after Arthur Schopenhauer. Snail&Voice: Confidential.        |

Web: http://www.eskimo.com/~schop Anonymous FTP: ftp.eskimo.com:/u/s/schop |
UltiNet: 97:200/261 FidoNet: 2:406/119 DisasterNet: 206:9721/204           |
PowerNet: 23:606/6                                                         |
Interests: Philosophy, Music, Vegeterian cooking, Programming, Sleeping.   |
--------------- Save the planet - kill yourself! --------------------------+



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug

Quote:



>> I've encountered quite an awkward bug when writing linked lists with
>> BP 7.0 OOP. When you're using the macro Inc with pointers, it will
>> do the increment incorrectly.

>> Inc(SomePtr, SizeOf(SomePtrType));

>> In this context SomePtr is a pointer-to-object, and SomePtrType is the
>> pointer type used to declare SomePtr. When the increment is executed,

Err.... say that again? Is SomePtrType a POINTER TYPE, or is it just
used to help DECLARE the pointer? Example :

type
        SomePtrType = record
                                this : word;
                                that : string;
                                theother : complextype;
                            end;
var
        SomePtr : ^SomePtrType;

if your code looks anything like this, the 'inc' will increment by the
amount of data space being referred to, because SomePtrType refers to
the DATA, not the pointer.

If I'm on the wrong track altogether, ignore me, flame me, whatever.

Ken Pemberton

Opinions expressed in this message do not necessarily
reflect those of myself, my organisation or anybody else.
I don't know where they come from... it scares me sometimes.



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug

Quote:
> Hi!

> I've encountered quite an awkward bug when writing linked lists with
> BP 7.0 OOP. When you're using the macro Inc with pointers, it will
> do the increment incorrectly.

Sorry, the Pascal procedure Inc cannot be used to manipulate pointers
as pointers are not ordinal types. Borland Pascal refuses to compile such
code. BTW, what "macro" ? Inc is a procedure, I never heard of a macro
in Pascal.

Quote:
> Olaf Martens

> To be mistaken is humane - but for real chaos you need a computer!

Stephan

-------------------------------------------------------------------------

       <<< Bug is a registered trademark of Microsoft Corp. >>>
-------------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug

Quote:


>: Inc(SomePtr, SizeOf(SomePtrType));
>Why not try
>Inc(Longint(SomePtr), 2);
>You know the length of SomePtr, dont you.

Be careful that you do not mean to say "sizeof(somePtrType^)"

The size of a pointer is 4 bytes.  The size of what the pointer points-to can
be different.

/mr/



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug
: Inc(SomePtr, SizeOf(SomePtrType));

Why not try
Inc(Longint(SomePtr), 2);

You know the length of SomePtr, dont you.
--
 - Patrik Hall ------------------ http://www.vtyh.fi/~phall/ -

 FIN-65100 Vaasa       X.400:/S=phall/O=vtyh/ADMD=fumail/C=fi/  



Wed, 18 Jun 1902 08:00:00 GMT  
 Borland Pascal 7.0 Bug
Quote:

>Sorry, the Pascal procedure Inc cannot be used to manipulate pointers

Gee, I must be getting phantom code generated then... It will, if you're using
the right compiler options, I use it all the time.. but you have to be
careful about what it's actually doing.
Quote:
>as pointers are not ordinal types. Borland Pascal refuses to compile such
>code. BTW, what "macro" ? Inc is a procedure, I never heard of a macro
>in Pascal.

Nope, but if you look, you'll see that the borland online help (windows)
(somewhat incorrectly) refers to 'macros', which are all just typecasts.

Will Bryant



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Fast pentium/Borland Pascal 7.0/crt bug question

2. I would like to know the difference between Borland Pascal 7.0 and Turbo Pascal 7.0

3. Turbo Pascal 7.0 vs Borland Pascal 7.0

4. Bug in borland pascal when reassign LST?

5. Borland Pascal memory problem - is there a bug?

6. Bug in Borland Pascal / Delphi

7. Borland Pascal 7.0 on 1.8Ghz plus computers.

8. Need replacement disks for Borland Pascal 7.0

9. WTB: Borland Turbo Pascal 7.0 for DOS and Windows

10. Borland Pascal 7.0

11. Metawindow 5.0 with Borland pascal 7.0 app crashes under win2K

 

 
Powered by phpBB® Forum Software