定义非static的未初始化的全局变量是流氓行为

本文详细解析了C语言中的程序结构和变量类型,包括变量声明、内存分配、运算符使用等核心概念,通过具体实例展示了如何在C语言中进行基本的程序设计。
/*
 * a.c
 *
 *  Created on: 2013-7-16
 *      Author: root
 */


int a = 1;

void test_a()
{
	printf("a:%d %d %d\r\n", &a, sizeof(a), a);
}


/*
 * b.c
 *
 *  Created on: 2013-7-16
 *      Author: root
 */

struct { int x; int y; } a;

void test_b()
{
	printf("b:%d %d %d %d\r\n", &a, sizeof(a), a.x, a.y);
}

/*
 * main.c
 *
 *  Created on: 2013-7-16
 *      Author: root
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
	test_a();
	test_b();

	return EXIT_SUCCESS;
}


结果:


a:6294340 4 1

b:6294340 8 1 0




#include "usrconf.h" #include "ucl_opreg.h" #include "ucRogueApDetect.h" #include "opRogueApDetect_info.h" #include "utility_debug.h" #include "utility_lib.h" /**************************************************************************************************/ /* DEFINES */ /**************************************************************************************************/ /**************************************************************************************************/ /* TYPES */ /**************************************************************************************************/ /**************************************************************************************************/ /* VARIABLES */ /**************************************************************************************************/ static ROGUE_AP_CONFIG *l_pRogueApCfg = NULL; static BOOL l_uc_rogueap_reset(cJSON *pDftData); static UINT32 l_uc_rogueap_getSize(); static void l_uc_rogueap_setBase(void *pBase); static cJSON* l_uc_rogueap_dataToJson(); static BOOL l_uc_rogueap_jsonToData(cJSON *pData); static void l_uc_rogueap_init(); static const UCL_UC_MODULE_INFO l_rogueapInfo = { "uc_rogueApDetect", l_uc_rogueap_init, l_uc_rogueap_reset, l_uc_rogueap_getSize, l_uc_rogueap_setBase, l_uc_rogueap_dataToJson, l_uc_rogueap_jsonToData, }; /**************************************************************************************************/ /* FUNCTIONS */ /**************************************************************************************************/ static BOOL l_uc_rogueap_reset(cJSON *pDftData) { if (NULL == pDftData) { return FALSE; } memset((void* )l_pRogueApCfg, 0, sizeof(ROGUE_AP_CONFIG)); l_pRogueApCfg->bEnabled = FALSE; l_uc_rogueap_jsonToData(pDftData); return TRUE; } static UINT32 l_uc_rogueap_getSize() { return GET_ALIGNED_SIZE(ROGUE_AP_CONFIG, 1); } static void l_uc_rogueap_setBase(void *pBase) { l_pRogueApCfg = (ROGUE_AP_CONFIG *)pBase; } static cJSON* l_uc_rogueap_dataToJson() { cJSON* pJson = NULL; cJSON* pTable = NULL; cJSON* pEntry = NULL; char macStr[MAC_STR_LEN] = {0}; int index = 0; pJson = cJSON_CreateObject(); if (NULL == pJson) { UTILDBG_ERROR(UCL_ROGUEAP_MODULE_NAME,"pJson is NULL."); return NULL; } cJSON_AddItemToObject(pJson, "enable", cJSON_CreateBool(l_pRogueApCfg->bEnabled)); cJSON_AddItemToObject(pJson, "macTable", pTable = cJSON_CreateArray()); return pJson; } static BOOL l_uc_rogueap_jsonToData(cJSON *pData) { char bssid[WLAN_MAC_ADDR_LEN] = {0}; int index = 0; int count = 0; cJSON *pTable = NULL; cJSON *pEntry = NULL; cJSON *pItem = NULL; if (NULL == pData) { UTILDBG_ERROR(UCL_ROGUEAP_MODULE_NAME,"pData is NULL."); return FALSE; } pItem = cJSON_GetObjectItem(pData, "enable"); if ((NULL != pItem) && (cJSON_True == pItem->type || cJSON_False == pItem->type)) { l_pRogueApCfg->bEnabled = pItem->type; } else { l_pRogueApCfg->bEnabled = FALSE; } pTable = cJSON_GetObjectItem(pData, "macTable"); return TRUE; } static void l_uc_rogueap_init() { return; } /**************************************************************************************************/ /* PUBLIC FUNCTIONS */ /**************************************************************************************************/ BOOL uc_rogueap_getEnable(void) { return l_pRogueApCfg->bEnabled; } UCL_RET uc_rogueap_setEnable(BOOL bEnabled) { l_pRogueApCfg->bEnabled = bEnabled; return UCL_OK; } UCL_RET uc_rogueap_getCfg(ROGUE_AP_CONFIG *pCfg) { if (NULL == pCfg) { return UCL_ERROR; } memcpy((void *)pCfg, (void *)l_pRogueApCfg, sizeof(ROGUE_AP_CONFIG)); return UCL_OK; } UCL_RET uc_rogueap_setCfg(ROGUE_AP_CONFIG *pCfg) { if (NULL == pCfg) { return UCL_ERROR; } memcpy((void *)l_pRogueApCfg, (void *)pCfg, sizeof(ROGUE_AP_CONFIG)); return UCL_OK; } UCL_RET uc_rogueap_cfg_setup(int modelIndex) { return ucl_op_addUcMod(modelIndex, (const UCL_UC_MODULE_INFO *)&l_rogueapInfo); } 代码分析,要求尽量详细
最新发布
09-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值