NJU-ProjectN / nemu

NJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching
Other
858 stars 184 forks source link

Header File Ordering Problem in 'abstract-machine/am/src/native/ioe/audio.c' #72

Closed ZJY0516 closed 1 year ago

ZJY0516 commented 1 year ago

I use clang format in vscode. However, I've encountered an issue where header files are automatically sorted, causing unexpected changes as illustrated below:

--- a/abstract-machine/am/src/native/ioe/audio.c
+++ b/abstract-machine/am/src/native/ioe/audio.c
@@ -1,8 +1,8 @@
#define _GNU_SOURCE
+#include <SDL2/SDL.h>
#include <fcntl.h>
-#include <unistd.h>
#include <klib.h>
-#include <SDL2/SDL.h>
+#include <unistd.h>

This leads to compilation error:

abstract-machine/am/src/native/ioe/audio.c: In function ‘__am_audio_init’:
abstract-machine/am/src/native/ioe/audio.c:13:15: error: implicit declaration of function‘pipe2’; did you mean ‘pipe’? [-Werror=implicit-function-declaration]
13 |     int ret = pipe2(fds, O_NONBLOCK);
|               ^~~~~
|               pipe
cc1: all warnings being treated as errors

Would it be possible to consider adding a comment or notice in the codebase to emphasize this behavior? It would be helpful to prevent such sorting of header files and subsequent compilation errors.

sashimi-yzh commented 1 year ago

This issue is unrelated to the codebase. Try to search the Internet for solution.

To help others who encounter the same issue, I leave this issue here.