This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
I’ve been experimenting with the Delphi hinting directives lately to make it easier to migrate some libraries to newer versions of Delphi and newer platforms.
Up to Delphi 5 you didn’t have any means to declare code obsolete. You had to find clever ways around it.
Warnings for hinting directives
When referring to identifiers marked with a hinting directive, you can get various warning messages that depend on the kind of identifier: unit, or other symbol. Read the rest of this entry »
Like any syntax highlighter, it is not perfect (only a Delphi compiler driven highlighter would have a chance to be perfect), but it does a pretty good job and gets better over time.
In other words: any language that merges null behaviour in the underlying storage will have a problem somwehere.
So if you want to have true nullable types, your null flag should be stored outside the underlying storage.
The .NET framework 2 and up, most database management systems and many other environment support that.
But most languages don’t support it for pointer types. So there will be portions of address spaces either inaccessible, or only accessible when skipping the null pointer checks.
Note that the thread above contains some very interesting bits, for instance this one:
Matt 28 Mar 2013 5:58 PM #
@MarkY “Dereferencing null is undefined? Cool! I thought it was guaranteed to crash, just like a false assertion or something. So crashing is the OS guarantee, not the language guarantee apparently.”
Nope. It’s not an OS guarantee either. The OS won’t ever normally allocate memory at address zero, but there’s nothing to stop you telling it to. Try doing “VirtualAlloc(1, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)” on your pre-Windows8 machine.
In fact, this is the reason why null-dereferences in kernel mode are often exploitable as elevation of privilege attacks. The null-page is mappable and within the user-addressable region of memory, so if the kernel dereferences a null pointer, it reads attacker controllable data.
And btw, this is the reason why on Linux and Windows8+ you can’t map the null-page.
Even in unsuspiciously looking code, the wit statement can bite you, especially if you need to do refactoring and (because of that) introduce two names in the same scope.
Whilst upgrading the code to remove the Containers unit (its not supported on NextGen platforms, so I have to make things work with Generics.Collections instead, (bye bye D7 support for this code) and refactor a couple stupidities in my original design (they always creep in, don’t they) I ended up with two class members of the same name. The with block then looked OK but I was in fact not access the member I thought I was.
Edit 20250102: added various “[Wayback/Archive]” archival links, VMware information, amended TUWA location, and added alternative csboot.zip download location on the Internet Archive (the Wayback Machine download is broken and the original gone)
Edit 20250102: does not work under VMware Fusion when you run Apple Silicon. Not figured out a performant alternative yet. Will try figuring out later.
Posts about the with statement usually cause a stir: people either like or dislike it with passion.
Starting with some history and examples, this posts lists a few DOs and DON’Ts when using the with statement, shows advantages and drawbacks, and shows you tools to eliminate with statements. Read the rest of this entry »