'Passing FILE* from fopen in stdio.h to u_finit in ustdio.h then call u_fgetc will trigger unhandled exception error for u_fgetc

This is what confused me so far. Apparently passing FILE* from fopen in stdio.h to u_finit in ustdio.h then call u_fgetc will trigger unhandled exception error for u_fgetc (file and ufile have NULL check in my actual code)

But looks like instead of that I just call u_fopen then u_fgetc will works as expected.

FILE* file = fopen("path/to/file.txt", "rb"); // Apparently both "r" and "rb" will have same issue
UFILE* ufile = u_finit(file, NULL, NULL);
UChar uchar = u_fgetc(ufile);

Did I do something wrong? The ICU documentation said I can pass FILE* to f_init but nothing mentions about unhandled exception error (docs link).

The assertion error happened on Visual Studio 2022. In gcc the program simply crash (nothing, even there's no Segmentation Fault).

Why do I want to do this? because there's no equivalent to ftell, fseek and fgetpos, fsetpos in icu. Also looks like someone asked this before but no answer to it beside the "hack" answer. I have tried to call fgetpos on u_fgetfile but it also cause assert error. Probably I should open separate question in regard to this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source