Recent

Author Topic: Can Absolute be used on string / packed record  (Read 2888 times)

Warfley

  • Hero Member
  • *****
  • Posts: 910
Re: Can Absolute be used on string / packed record
« Reply #75 on: July 01, 2022, 09:18:15 pm »
You do have a point there but, that kind of mistake can be avoided by specifying {$TYPEDADDRESS ON} (the above does _not_ compile.)  Unfortunately, it isn't the default (another Borland-ism likely due to the fact that making it the default would have prevented existing code from compiling.)


Ideally, {$TYPEDADDRESS ON} should be the compiler's intrinsic behavior, IOW, not even an option and, if for some reason someone wants to retype a variable (which is what that code does) then, using "absolute" is the proper method (though obviously in this case, it would be used incorrectly.)
Thats quite neat, didn't know about this compiler switch, this is going to be in every of my projects dealing with pointers from now on :)

440bx

  • Hero Member
  • *****
  • Posts: 2933
Re: Can Absolute be used on string / packed record
« Reply #76 on: July 01, 2022, 09:39:46 pm »
this is going to be in every of my projects dealing with pointers from now on :)
That directive is at the top of every one of my units. :)

ETA:

we agreed on something... a historical moment!  :D
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

MarkMLl

  • Hero Member
  • *****
  • Posts: 4753
Re: Can Absolute be used on string / packed record
« Reply #77 on: July 01, 2022, 10:27:54 pm »
I hate classes in object pascal exactly because they hide the pointer. ... Code should at all times give you all the information you need to understand that code,

I'm inclined to agree, but the same criticism also applies to overuse of dots (i.e. the way that they conceal a property's getter or setter) and the discussion of that in the context of the Pascal family of languages predates Delphi.

I know this would upset Sven, but since he's not risen to my request that he comment on the adequacy of untagged variant records in the context of generic pointers I presume he's skipping this thread. But I frankly I'd be happier if the core language, even if it did have facilities for reference-counted managed entities etc., made no attempt to sugar the syntax; instead outside the core language have a tasty fleshy layer, with a trait-based inheritance system which was able to specify that e.g. "a reference of this type should be automagically dereferenced" as well as "this type of cast may be performed implicitly" etc. (both of those examples amount to "here's how to make type X compatible with type Y", and I think it's reasonable to teach a compiler that trick).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4303
  • Compiler Developer
Re: Can Absolute be used on string / packed record
« Reply #78 on: July 02, 2022, 04:29:53 pm »
Examples that come to mind are in compare functions for routines such as qsort and bsearch or any other routine that uses generic pointers.  In those cases, the simplest, cleanest and correct solution is to "absolute" variable declarations with the proper type on top of the generic pointers.  Without "absolute" every use of the generic pointer would require a typecast.

"absolute" is by far, the cleanest way of "dis-ambiguating" accesses to structures such as the optional header or the import thunks, those two among thousands of similar situations.

I'd like to see @PascalDragon comment on that. The core question is whether an untagged variant record can be used in this context, i.e. with the currently-assumed type indicated by a named field, or whether it /has/ to be done using absolute.

I have absolutely no idea how a untagged variant record would come into play here. For functions that take plain Pointer parameters, but where you know the type of the pointer (e.g. the mentioned compare functions or a function that has some kind of context pointer parameter like e.g. in the compiler's foreachnodestatic functions) absolute is by far the easiest and quickest way to get the correct type (you can't check the type anyway here).

I know this would upset Sven, but since he's not risen to my request that he comment on the adequacy of untagged variant records in the context of generic pointers I presume he's skipping this thread.

I'm only skimming this thread, cause when I see Warfley and 440bx throwing walls of text against each other I'll just throw out a “nope” and walk away.

But I frankly I'd be happier if the core language, even if it did have facilities for reference-counted managed entities etc., made no attempt to sugar the syntax; instead outside the core language have a tasty fleshy layer, with a trait-based inheritance system which was able to specify that e.g. "a reference of this type should be automagically dereferenced" as well as "this type of cast may be performed implicitly" etc. (both of those examples amount to "here's how to make type X compatible with type Y", and I think it's reasonable to teach a compiler that trick).

Feel free to start your own language then. With Object Pascal and Free Pascal this isn't going to happen.

MarkMLl

  • Hero Member
  • *****
  • Posts: 4753
Re: Can Absolute be used on string / packed record
« Reply #79 on: July 02, 2022, 04:41:59 pm »
I have absolutely no idea how a untagged variant record would come into play here. For functions that take plain Pointer parameters, but where you know the type of the pointer (e.g. the mentioned compare functions or a function that has some kind of context pointer parameter like e.g. in the compiler's foreachnodestatic functions) absolute is by far the easiest and quickest way to get the correct type (you can't check the type anyway here).

OK thanks, noted. Is Warfley's mention of $TYPEDADDRESS relevant to this?

Quote
I'm only skimming this thread, cause when I see Warfley and 440bx throwing walls of text against each other I'll just throw out a “nope” and walk away.

GRIN

Quote
Feel free to start your own language then. With Object Pascal and Free Pascal this isn't going to happen.

I know, and we've been through this before. But I thought it was fair comment in response to what Warfley was saying.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4303
  • Compiler Developer
Re: Can Absolute be used on string / packed record
« Reply #80 on: July 02, 2022, 04:48:05 pm »
I have absolutely no idea how a untagged variant record would come into play here. For functions that take plain Pointer parameters, but where you know the type of the pointer (e.g. the mentioned compare functions or a function that has some kind of context pointer parameter like e.g. in the compiler's foreachnodestatic functions) absolute is by far the easiest and quickest way to get the correct type (you can't check the type anyway here).

OK thanks, noted. Is Warfley's mention of $TYPEDADDRESS relevant to this?

$TYPEDADDRESS simply assures that @SomeVar returns ^TypeOf(SomeVar) instead of Pointer (Addr(SomeVar) in contrast always returns a Pointer). If you already have a pointer then this makes no difference.

 

TinyPortal © 2005-2018