Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-11

Proper way to cast dynamic array in watch window?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jim Leonard

Using the FPC console IDE. When I define a typed array with limits, ie.:

type
   tbarray=array[0..1023] of byte;
var
   foo:tbarray;

...I can view the contents of in the watch window (like "foo[2]") without problems. But if I define it as a dynamic array:

type
   tbarray=array of byte;
var
   foo:tbarray;
...
setlength(foo,1024);

...then trying to view the array ("foo[2]") in the watch window shows up as "Cannot perform pointer math on incomplete types, try casting to a known type, or void *". I've tried casting like byte(foo[2]) and byte^(foo[2]) but I must be doing it wrong as those aren't working.

What is the proper way to cast dynamic arrays so that I can inspect them in the watch window?

Jim Leonard () Check out some trippy MindCandy: http://www.mindcandydvd.com/ A child borne of the home computer wars: http://trixter.oldskool.org/ You're all insane and trying to steal my magic bag!

Reply by email

Jürgen Hestermann
to Jim Leonard
Jim Leonard wrote 15 lines
Using the FPC console IDE. When I define a typed array with limits, ie.: type tbarray=array[0..1023] of byte; var foo:tbarray; ...I can view the contents of in the watch window (like "foo[2]") without problems. But if I define it as a dynamic array: type tbarray=array of byte; var foo:tbarray; ... setlength(foo,1024); ...then trying to view the array ("foo[2]") in the watch window shows up as "Cannot perform pointer math on incomplete types, try casting to a known type, or void *". I've tried casting like byte(foo[2]) and byte^(foo[2]) but I must be doing it wrong as those aren't working. What is the proper way to cast dynamic arrays so that I can inspect them in the watch window?

Dynamic arrays are actually *pointer* to arrays.
The compiler hides this fact from you because it automatically dereferences the pointer when you use an index:

foo[i]
will be automatically expanded to
foo^[i]

But the debugger is not able to do this.
So you need to write

foo^[i]

when you want to examine this value in watch window or other debug windows.

Reply by email