a question about POSIX fgetc
Pietro Monteiro
pietro.gcc@sociotechnical.xyz
Fri Jul 3 15:48:50 GMT 2026
On Thu, Jul 2, 2026, at 10:29 PM, chris hermansen wrote:
> Good evening all;
>
> At https://gcc.gnu.org/onlinedocs/ga68/POSIX-string-transput.html I see
> fgetc defined as:
>
> Procedure: *fgetc* `= (*int* fd) *int*`
> <https://gcc.gnu.org/onlinedocs/ga68/POSIX-string-transput.html#index-fgetc>
> Read a character from the file with descriptor `fd`. This procedure
> yields the read character in case a valid Unicode character got
> successfully read. If an unrecognizable or unknown character is found
> then this procedure yields `replacement char`. In case of end of file
> this procedure yields `eof char`.
>
> However when I look in libga68/posix.a68 I see:
>
> pub proc(int)char fgetc = nest C "_libga68_posixfgetc";
>
> Digging further into libga68/ga68-posix.c I see that
> _libga68_posixfgetc returns uint32_t and the values can be
> EOF_PSEUDO_CHARACTER (== -1), REPLACEMENT_CHARACTER (0xFFFD) or the
> successfully decoded uint32_t "res".
>
> My C ignorance is showing here but I'm having difficulty understanding
> what -1 or 0xFFFD look like when returned as unit32_t and what those
> values end up looking like in GNU Algol 68.
We use UTF-32 for chars, so the C unit32_t will be a regular char on the A68 side.
0xFFFD is the “question mark in a box” (�).
-1 will become 0xFFFFFF, since we use an unsigned type.
> Should I be doing something like
>
> int ic = REPR fgetc(fd) so that I can check to see if I've hit end of
> file or a replacement character?
You can use the “string break” notation "'(uhhhh)" or "'(Uhhhhhhhh)”\
https://gcc.gnu.org/onlinedocs/gcc-16.1.0/ga68/String-breaks.html
> Please advise!
Hope that helps.
pietro
> --
> Chris Hermansen · clhermansen "at" gmail "dot" com
>
> C'est ma façon de parler.
More information about the Algol68
mailing list