Guarding against uninitialized variables RFC
Iain Sandoe
iain@sandoe.co.uk
Sun Jun 21 22:46:23 GMT 2026
> On 21 Jun 2026, at 23:03, Jose E. Marchesi <jemarch@gnu.org> wrote:
>
>
>> Good day everyone,
>>
>> After 10 days away from almost everything to do with computers in order to
>> concentrate on Important Stuff (like beaches), I'm back prodding van
>> Vliet's transput.
>>
>> The open, establish and create procedures will fail with a non-zero return
>> code if they cannot establish the linkage between File, Channel, Book and
>> the operating system file. However this can leave the nonpublic Book
>> variable in an uninitialized state.
>>
>> Of course, I can initialize the Book variable to some pattern that I can
>> later interpret as meaning no linkage was created; and I can check wherever
>> that Book variable is used to make sure it has a valid linkage.
>>
>> But I don't believe there is a way to detect uninitialized variables other
>> than this.
>>
>> Does anyone have any suggestions? Thanks in advance!
>
> I think there is no way.
>
> In strict Algol 68 the value actually held by uninitialized variables is
> undefined.
>
> In GNU Algol 68 uninitialized variables all have a predictable value: 0
> for int, 0.0 for real, " " for char, etc.
>
> But that will not really help to detect uninitialized variables.
>
> I would look to declare a no_book identifier with some distinguishable
> value ascribed to it, then get the books initialized to it, then check
> for it before accesses. Alternatively, you could add an additional
> book_initialized boolean..
>
You might want to look at what C++ is doing with “Erroneous behaviour”
and marking vars as uninitilised. There’s no really good value that can
be used to indicate this - some “on the side” meta-data seems needed.
Perhaps a bit on a var decl would be worth allocating.
"maybe uninitialised" warnings are not the most popular...
Iain
More information about the Algol68
mailing list