开始设计

This commit is contained in:
2026-08-10 01:21:15 +08:00
commit e45398991f
228 changed files with 20827 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
#include <c_Base.h>
+21
View File
@@ -0,0 +1,21 @@
#ifndef INCLUDED_C_BASE_H
#define INCLUDED_C_BASE_H
#ifndef INCLUDED_C_CONFIG_H
#include <c_Config.h>
#endif /*INCLUDED_C_CONFIG_H*/
#ifndef INCLUDED_C_TYPES_H
#include <c_Types.h>
#endif /*INCLUDED_C_TYPES_H*/
#ifndef INCLUDED_C_COMPILER_H
#include <c_Compiler.h>
#endif /*INCLUDED_C_COMPILER_H*/
#ifndef INCLUDED_C_MACROS_H
#include <c_Macros.h>
#endif /*INCLUDED_C_MACROS_H*/
#endif /*INCLUDED_C_BASE_H*/
+13
View File
@@ -0,0 +1,13 @@
#include <c_Compiler.h>
#if defined(__GNUC__) && !defined(__clang__)
#include "c_Compiler_GNUC.c"
#endif
#if defined(__clang__)
#include "c_Compiler_CLANG.c"
#endif
#if defined(_MSC_VER)
#include "c_Compiler_MSVC.c"
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef INCLUDED_C_COMPILER_H
#define INCLUDED_C_COMPILER_H
#if defined(__GNUC__) && !defined(__clang__)
#include "c_Compiler_GNUC.h"
#endif
#if defined(__clang__)
#include "c_Compiler_CLANG.h"
#endif
#if defined(_MSC_VER)
#include "c_Compiler_MSVC.h"
#endif
#endif /*INCLUDED_C_COMPILER_H*/
+16
View File
@@ -0,0 +1,16 @@
#include "c_Compiler.h"
#include <stdlib.h>
#include <stdio.h>
C_PACKED_STRUCT(
MyPackedStruct{
char id;
int value;
short status;
});
int main(int argc, char** argv){
struct MyPackedStruct packed_struct={0};
return 0;
}
+1
View File
@@ -0,0 +1 @@
#include <c_Compiler_CLANG.h>
+8
View File
@@ -0,0 +1,8 @@
#ifndef INCLUDED_C_COMPILER_CLANG_H
#define INCLUDED_C_COMPILER_CLANG_H
#define C_STATIC_FORCE_INLINE static inline __attribute__((always_inline))
#define C_PACKED_STRUCT(X) struct X __attribute__((packed))
#endif /*INCLUDED_C_COMPILER_CLANG_H*/
+1
View File
@@ -0,0 +1 @@
#include <c_Compiler_GNUC.h>
+8
View File
@@ -0,0 +1,8 @@
#ifndef INCLUDED_C_COMPILER_GNUC_H
#define INCLUDED_C_COMPILER_GNUC_H
#define C_STATIC_FORCE_INLINE static inline __attribute__((always_inline))
#define C_PACKED_STRUCT(X) struct X __attribute__((packed))
#endif /*INCLUDED_C_COMPILER_GNUC_H*/
+1
View File
@@ -0,0 +1 @@
#include <c_Compiler_MSVC.h>
+16
View File
@@ -0,0 +1,16 @@
#ifndef INCLUDED_C_COMPILER_MSVC_H
#define INCLUDED_C_COMPILER_MSVC_H
#if _MSC_VER >= 1920
// Visual Studio 2019 或更新版本
#elif _MSC_VER >= 1910
// Visual Studio 2017
#elif _MSC_VER >= 1900
// Visual Studio 2015
#endif
#define C_STATIC_FORCE_INLINE static inline __forceinline
#define C_PACKED_STRUCT(X) __pragma(pack(push, 1)) struct X __pragma(pack(pop))
#endif /*INCLUDED_C_COMPILER_MSVC_H*/
+1
View File
@@ -0,0 +1 @@
#include <c_Macros.h>
+119
View File
@@ -0,0 +1,119 @@
#ifndef INCLUDED_C_MACROS_H
#define INCLUDED_C_MACROS_H
#ifndef INCLUDED_MATH_H
#define INCLUDED_MATH_H
#include <math.h>
#endif /*INCLUDED_MATH_H*/
#ifndef INCLUDED_C_TYPES_H
#include <c_Types.h>
#endif /*INCLUDED_C_TYPES_H*/
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_MIN(a, b) ((a) < (b) ? (a) : (b))
#define C_MAX(a, b) ((a) > (b) ? (a) : (b))
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_RAD2DEG(x) ((x)/M_PI*180.0)
#define C_DEG2RAD(x) ((x)*M_PI/180.0)
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_ALIGN_UPB(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
#define C_ALIGN_UP(x, align) ((((x) + ((align) - 1)) / (align)) * (align))
#define C_ALIGN_DOWNB(x, align) ((x) & ~((align) - 1))
#define C_ALIGN_DOWN(x, align) (((x) / (align)) * (align))
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_CLIP(x, min, max) (((x) < (min)) ? (min) : \
(((x) > (max)) ? (max) : (x)))
#define C_MAX_CLIP(x, max) (((x) > (max)) ? (max) : (x))
#define C_MIN_CLIP(x, min) (((x) < (min)) ? (min) : (x))
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_ABS(x) (((x) < 0) ? -(x) : (x))
#define C_DIFF(a,b) C_ABS((a)-(b))
#define C_IS_NAN(x) ((x) != (x))
#define C_COMPARE(x, y) (((x) > (y)) - ((x) < (y)))
#define C_SIGN(x) C_COMPARE(x, 0)
#define C_IS_ODD( num ) ((num) & 1)
#define C_IS_EVEN( num ) (!IS_ODD( (num) ))
#define C_IS_BETWEEN(n,L,H) ((unsigned char)((n) >= (L) && (n) <= (H)))
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_BIT(x) (1<<(x))
#define C_BIT_SET(x,p) ((x)|(1<<(p)))
#define C_BIT_CLEAR(x,p) ((x)&(~(1<<(p))))
#define C_BIT_GET(x,p) (((x)>>(p))&1)
#define C_BIT_TOGGLE(x,p) ((x)^(1<<(p)))
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define C_SET(d, n, v) do{ c_size_t i_, n_; \
for ( n_ = (n), i_ = 0; n_ > 0; --n_, ++i_) \
(d)[i_] = (v); } while(0)
#define C_ZERO(d, n) C_SET(d, n, 0)
#define C_COLUMNS(S,E) ( (E) - (S) + 1 )
#define C_IS_ARRAY(a) ((void *)&a == (void *)a)
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_STMT( stuff ) do { stuff } while (0)
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
// 1. 底层拼接宏(真正执行拼接)
#define C_UNIQUE_NAME_CONCAT(a, b) a ## b
// 2. 中间转换宏(强制将 __LINE__ 或 __COUNTER__ 展开为实际的数字/符号)
#define C_UNIQUE_NAME_EVAL(a, b) C_UNIQUE_NAME_CONCAT(a, b)
// 3. 面向用户的唯一名称生成宏
#if defined(__COUNTER__)
// 工业级推荐:__COUNTER__ 从 0 开始,每次调用自动递增,保证绝对唯一
#define C_UNIQUE_NAME(prefix) C_UNIQUE_NAME_EVAL(prefix, __COUNTER__)
#else
// 兼容标准:__LINE__ 使用当前行号,同一行内多次调用可能会冲突
#define C_UNIQUE_NAME(prefix) C_UNIQUE_NAME_EVAL(prefix, __LINE__)
#endif
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_ONCE2(stmts, var) {static int var = 1;\
if(var){stmts\
var = 0;}}
#define C_ONCE(stmts) C_ONCE2(stmts, C_UNIQUE_NAME(__onceVar__))
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_CONTAINER_OF(ptr, type, member) \
((type *)( (char *)(ptr) - offsetof(type, member) ))
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define C_UNUSED(x) ((void)(x))
#endif /*INCLUDED_C_MACROS_H*/
+9
View File
@@ -0,0 +1,9 @@
#include "c_Macros.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv){
return 0;
}
+1
View File
@@ -0,0 +1 @@
#include <c_Types.h>
+130
View File
@@ -0,0 +1,130 @@
#ifndef INCLUDED_C_TYPES_H
#define INCLUDED_C_TYPES_H
#ifndef INCLUDED_C_CONFIG_H
#include <c_Config.h>
#endif /*INCLUDED_C_CONFIG_H*/
#ifndef INCLUDED_STDINT_H
#define INCLUDED_STDINT_H
#include <stdint.h>
#endif /*INCLUDED_STDINT_H*/
#ifndef INCLUDED_STDBOOL_H
#define INCLUDED_STDBOOL_H
#include <stdbool.h>
#endif /*INCLUDED_STDBOOL_H*/
#ifndef INCLUDED_STDATOMIC_H
#define INCLUDED_STDATOMIC_H
#include <stdatomic.h>
#endif /*INCLUDED_STDATOMIC_H*/
#ifndef INCLUDED_STRING_H
#define INCLUDED_STRING_H
#include <string.h>
#endif /*INCLUDED_STRING_H*/
#ifndef INCLUDED_TIME_H
#define INCLUDED_TIME_H
#include <time.h>
#endif /*INCLUDED_TIME_H*/
#ifndef INCLUDED_INTTYPES_H
#define INCLUDED_INTTYPES_H
#include <inttypes.h>
#endif /*INCLUDED_INTTYPES_H*/
#ifndef INCLUDED_ASSERT_H
#define INCLUDED_ASSERT_H
#include <assert.h>
#endif /*INCLUDED_ASSERT_H*/
#ifndef INCLUDED_FLOAT_H
#define INCLUDED_FLOAT_H
#include <float.h>
#endif /*INCLUDED_FLOAT_H*/
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#if (C_SIZEOF_VOID_P==4)
typedef int32_t c_int_t;
typedef uint32_t c_uint_t;
typedef uint32_t c_uintptr_t;
typedef int32_t c_intptr_t;
typedef int32_t c_ptrdiff_t;
typedef uint32_t c_size_t;
#define C_INT_MIN INT32_MIN
#define C_INT_MAX INT32_MAX
#define C_UINT_MAX UINT32_MAX
#define C_SIZE_MAX UINT32_MAX
#define C_PTRDIFF_MIN INT32_MIN
#define C_PTRDIFF_MAX INT32_MAX
#define C_PRId PRId32
#define C_PRIi PRIi32
#define C_PRIo PRIo32
#define C_PRIu PRIu32
#define C_PRIx PRIx32
#define C_PRIX PRIX32
#define C_SCNd SCNd32
#define C_SCNi SCNi32
#define C_SCNo SCNo32
#define C_SCNu SCNu32
#define C_SCNx SCNx32
#elif (C_SIZEOF_VOID_P==8)
typedef int64_t c_int_t;
typedef uint64_t c_uint_t;
typedef uint64_t c_uintptr_t;
typedef int64_t c_intptr_t;
typedef int64_t c_ptrdiff_t;
typedef uint64_t c_size_t;
#define C_INT_MIN INT64_MIN
#define C_INT_MAX INT64_MAX
#define C_UINT_MAX UINT64_MAX
#define C_SIZE_MAX UINT64_MAX
#define C_PTRDIFF_MIN INT64_MIN
#define C_PTRDIFF_MAX INT64_MAX
#define C_PRId PRId64
#define C_PRIi PRIi64
#define C_PRIo PRIo64
#define C_PRIu PRIu64
#define C_PRIx PRIx64
#define C_PRIX PRIX64
#define C_SCNd SCNd64
#define C_SCNi SCNi64
#define C_SCNo SCNo64
#define C_SCNu SCNu64
#define C_SCNx SCNx64
#endif
#define c_bool_t bool
#define C_TRUE true
#define C_FALSE false
typedef time_t c_time_t;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
typedef int c_err_t;
#define C_ERR_OK (0)
#define C_ERR_SUCCESS C_ERR_OK
#define C_ERR_FAIL (-1)
#define C_ERR_NOMEM (-2)
#define C_ERR_PARAM (-3)
#define C_ERR_FULL (-4)
#define C_ERR_EMPTY (-5)
#define C_ERR_INDEX (-6)
#define C_ERR_STATUS (-7)
#define C_ERR_NOT_FOUND (-8)
#define C_ERR_ALREADY_EXISTS (-9)
#define C_ERR_INVALID C_ERR_FAIL
#endif /*INCLUDED_C_TYPES_H*/