C语言命名规范 - Mon, Apr 3, 2023
C语言命名规范
1. 类型定义
/*! \brief Size : 8 bits Range : TRUE or FASE */
typedef unsigned char Boolean;
/*! \brief Size : 8 bits Range : 0 to 255 */
typedef unsigned char Unsigned8;
/*! \brief Size : 8 bits Range : -128 to 127 */
typedef signed char Integer8;
/*! \brief Size : 16 bits Range : 0 to 65,535 */
typedef unsigned short int Unsigned16;
/*! \brief Size : 16 bits Range : -32,768 to 32,767 */
typedef signed short int Integer16;
/*! \brief Size : 32 bits Range : 0 to 4,294,967,295 */
typedef unsigned long int Unsigned32;
/*! \brief Size : 32 bits Range : -2,147,483,648 to 2,147,483,647 */
typedef signed long int Integer32;
/*! \brief Size : 64 bits Range : 0 to 18,446,744,073,709,551,616 */
typedef unsigned long long int Unsigned64;
/*! \brief Size : 64 bits Range : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 */
typedef signed long long int Integer64;
/*! \brief Size : 128 bits Range : 0 to 18,446,744,073,709,551,616 (NOTE : Windows ONLY SUPPORTS 64 bits) */
typedef unsigned long long int Unsigned128;
/*! \brief Size : 128 bits Range : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (NOTE : Windows ONLY SUPPORTS 64 bits) */
typedef signed long long int Integer128;
/*! \brief Size : 32 bits Range : 1.175494e-38 to 3.402823e+38 */
typedef float Float32;
/*! \brief Size : 64 bits Range : 2.225074e-308 to 1.797693e+308 */
typedef double Float64;
/*! \brief Size : 128 bits Range : 2.225074e-308 to 1.797693e+308 */
typedef long double Float128;
/*! \brief Size : 16 bits Range : 0 to 65535 */
typedef wchar_t Unicode;
/*! \brief Size : Depends on the Platform */
typedef size_t UnSize;
2. 枚举声明
/*! List of commom error codes */
enum eErrorCodes
{
MD_OK = 0, /*!< No Error Code */
MD_ERROR = -1, /*!< Unknown Error */
MD_NOT_INIT = -3, /*!< Modbus Not Init */
MD_YAML_ERROR = -4, /*!< Yaml Error */
MD_URL_ERROR = -5, /*!< Url Error */
MD_SERVER_ERROR = -6, /*!< Server Error */
}PACKED;
3. 结构体声明
/*! \brief Device Settings Structure. */
struct sDevice
{
Integer8 ai8ID[MAX_STRING_LEN]; /*!< Device ID */
Unsigned32 u32Address; /*!< Device Address */
Integer8 ai8Name[MAX_STRING_LEN]; /*!< Device Name */
};
4. 变量名属性名定义
// 数组命名
Integer8 ai8ID[MAX_STRING_LEN];
// 非数组
Unsigned32 u32Address;
// 枚举
enum eKindofParameter eKPA;
// bool
Boolean bEnableRedundancy;
// 结构体
struct sDebugParameters sDebug;
// 指针
struct sObject *psIEC104Objects;
// void指针
void *pvData;