From b80f5815621a57b16671b2c5d64a279835654b99 Mon Sep 17 00:00:00 2001 From: tyx <462747508@qq.com> Date: Sat, 2 Apr 2022 16:21:45 +0800 Subject: [PATCH] [compilers] Fix c/c++ compilation warnings and errors --- components/drivers/include/ipc/workqueue.h | 8 +++++++- components/fal/src/fal_partition.c | 3 +++ components/fal/src/fal_rtt.c | 2 +- components/libc/compilers/common/extension/fcntl.h | 8 ++++++++ components/libc/compilers/common/extension/sys/select.h | 8 ++++++++ components/libc/compilers/common/extension/sys/stat.h | 8 ++++++++ components/libc/compilers/common/extension/sys/types.h | 8 ++++++++ components/libc/compilers/common/extension/sys/unistd.h | 8 ++++++++ components/libc/compilers/common/sys/ioctl.h | 8 ++++++++ components/libc/compilers/common/sys/statfs.h | 8 ++++++++ components/utilities/var_export/var_export.c | 2 +- 11 files changed, 68 insertions(+), 3 deletions(-) diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 7fc7650d74..acb8307bf7 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -13,6 +13,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + enum { RT_WORK_STATE_PENDING = 0x0001, /* Work item pending state */ @@ -70,7 +74,9 @@ rt_err_t rt_work_urgent(struct rt_work *work); rt_err_t rt_work_cancel(struct rt_work *work); #endif /* RT_USING_SYSTEM_WORKQUEUE */ - +#ifdef __cplusplus +} +#endif #endif /* RT_USING_HEAP */ diff --git a/components/fal/src/fal_partition.c b/components/fal/src/fal_partition.c index 9aee41e18c..94f88dbed5 100644 --- a/components/fal/src/fal_partition.c +++ b/components/fal/src/fal_partition.c @@ -43,6 +43,9 @@ struct part_flash_info #elif defined (__GNUC__) /* GNU GCC Compiler */ #define SECTION(x) __attribute__((section(x))) #define USED __attribute__((used)) +#elif defined (_MSC_VER) + #define SECTION(x) + #define USED #else #error not supported tool chain #endif /* __CC_ARM */ diff --git a/components/fal/src/fal_rtt.c b/components/fal/src/fal_rtt.c index 7747bff9e7..3a014525b2 100644 --- a/components/fal/src/fal_rtt.c +++ b/components/fal/src/fal_rtt.c @@ -875,7 +875,7 @@ static void fal(uint8_t argc, char **argv) { result = fal_partition_read(part_dev, i, read_data, cur_op_size); } /* data check */ - for (int index = 0; index < cur_op_size; index ++) + for (size_t index = 0; index < cur_op_size; index ++) { if (write_data[index] != read_data[index]) { diff --git a/components/libc/compilers/common/extension/fcntl.h b/components/libc/compilers/common/extension/fcntl.h index ac642abcbb..c3bf851523 100644 --- a/components/libc/compilers/common/extension/fcntl.h +++ b/components/libc/compilers/common/extension/fcntl.h @@ -13,6 +13,10 @@ #include "sys/types.h" +#ifdef __cplusplus +extern "C" { +#endif + #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 @@ -68,4 +72,8 @@ int open(const char *file, int flags, ...); int fcntl(int fildes, int cmd, ...); int creat(const char *path, mode_t mode); +#ifdef __cplusplus +} +#endif + #endif diff --git a/components/libc/compilers/common/extension/sys/select.h b/components/libc/compilers/common/extension/sys/select.h index 44f9b4ed91..8afc308fe1 100644 --- a/components/libc/compilers/common/extension/sys/select.h +++ b/components/libc/compilers/common/extension/sys/select.h @@ -20,6 +20,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + #ifndef FD_SETSIZE #define FD_SETSIZE 32 #endif @@ -55,4 +59,8 @@ typedef struct _types_fd_set { int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); #endif /* _WIN32 */ +#ifdef __cplusplus +} +#endif + #endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/common/extension/sys/stat.h b/components/libc/compilers/common/extension/sys/stat.h index 107c15decf..d0e6cc9140 100644 --- a/components/libc/compilers/common/extension/sys/stat.h +++ b/components/libc/compilers/common/extension/sys/stat.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define S_IFMT 00170000 #define S_IFSOCK 0140000 #define S_IFLNK 0120000 @@ -80,4 +84,8 @@ int mknod(const char *, mode_t, dev_t); int stat(const char *, struct stat *); mode_t umask(mode_t); +#ifdef __cplusplus +} +#endif + #endif diff --git a/components/libc/compilers/common/extension/sys/types.h b/components/libc/compilers/common/extension/sys/types.h index 85cd4fea21..1275803c37 100644 --- a/components/libc/compilers/common/extension/sys/types.h +++ b/components/libc/compilers/common/extension/sys/types.h @@ -16,6 +16,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef int32_t clockid_t; typedef int32_t key_t; /* Used for interprocess communication. */ typedef int pid_t; /* Used for process IDs and process group IDs. */ @@ -39,4 +43,8 @@ typedef unsigned int u_int; typedef unsigned char u_char; typedef unsigned long u_long; +#ifdef __cplusplus +} +#endif + #endif diff --git a/components/libc/compilers/common/extension/sys/unistd.h b/components/libc/compilers/common/extension/sys/unistd.h index 29ec3f70c4..2b8ca33260 100644 --- a/components/libc/compilers/common/extension/sys/unistd.h +++ b/components/libc/compilers/common/extension/sys/unistd.h @@ -15,6 +15,10 @@ #include #include "types.h" /* */ +#ifdef __cplusplus +extern "C" { +#endif + #define STDIN_FILENO 0 /* standard input file descriptor */ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */ @@ -46,4 +50,8 @@ uid_t geteuid(void); gid_t getgid(void); gid_t getegid(void); +#ifdef __cplusplus +} +#endif + #endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h index 0b1edca699..0243932cba 100644 --- a/components/libc/compilers/common/sys/ioctl.h +++ b/components/libc/compilers/common/sys/ioctl.h @@ -15,6 +15,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + struct winsize { unsigned short ws_row; @@ -271,4 +275,8 @@ struct winsize int ioctl(int fildes, int cmd, ...); +#ifdef __cplusplus +} +#endif + #endif diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/sys/statfs.h index a86a789475..6f92bf1cf3 100644 --- a/components/libc/compilers/common/sys/statfs.h +++ b/components/libc/compilers/common/sys/statfs.h @@ -12,6 +12,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct statfs { size_t f_bsize; /* block size */ @@ -22,4 +26,8 @@ struct statfs int statfs(const char *path, struct statfs *buf); int fstatfs(int fd, struct statfs *buf); +#ifdef __cplusplus +} +#endif + #endif diff --git a/components/utilities/var_export/var_export.c b/components/utilities/var_export/var_export.c index f4ab40c63a..5ab7e2b57e 100644 --- a/components/utilities/var_export/var_export.c +++ b/components/utilities/var_export/var_export.c @@ -83,7 +83,7 @@ int var_export_init(void) static char __vexp_strbuf1[1024]; static char __vexp_strbuf2[1024]; ve_exporter_t ve_exporter_temp; - int index_i, index_j; + rt_size_t index_i, index_j; /* past the three members in first ptr_begin */ ptr_begin += (sizeof(struct ve_exporter) / sizeof(unsigned int));