xiaoxiang781216 commented on pull request #425: URL: https://github.com/apache/incubator-nuttx-apps/pull/425#issuecomment-708586521
> This fixes the USB console for me, but note that this is still a workaround. No, it isn't a workaround, the old way is an undefined behaviour from https://pubs.opengroup.org/onlinepubs/9699919799/functions/fclose.html and we should avoid. > The following strictly conforming C program causes a crash on NuttX (tested in Flat mode build): > > ``` > #include <stdio.h> > > int main(void) > { > /* Note: order significant if want to see a crash on NuttX. */ > fclose(stdin); > fclose(stdout); > fclose(stderr); > /* ... can open some file here, read/write to it, close it. ... just don't call printf() */ > return 0; > } > ``` > > This kind of usage of fclose() is unlikely to appear in real programs, though. To improve the compability, I will provide a patch to ignore fclose to stdin/stdout/stderr anyway. > > Also note that fflush(stdin) is undefined behavior in C, but we can allow it since we are the implementor. Why is fflush(stdin) undefined? can you point me the related document? It's reasonable to expect that fflush(stdin) flush out the unread data in the buffer. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
