int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

Similar documents
CC213

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

FY.DOC

378高雄市都市計畫說明書

新版 明解C++入門編

新・明解C言語入門編『索引』

C 1

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

untitled

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

Microsoft Word - CIN-DLL.doc

C++ 程式設計

untitled

_汪_文前新ok[3.1].doc

51 C 51 isp 10 C PCB C C C C KEIL

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

C/C++语言 - C/C++数据

Microsoft Word - 11.doc

nooog

威 福 髮 藝 店 桃 園 市 蘆 竹 區 中 山 里 福 祿 一 街 48 號 地 下 一 樓 50,000 獨 資 李 依 純 105/04/06 府 經 登 字 第 號 宏 品 餐 飲 桃 園 市 桃 園 區 信 光 里 民

c_cpp

海 南 冯 琳 峰 海 南 省 锅 炉 压 力 容 器 与 特 种 设 备 检 验 所 海 南 省 定 安 县 白 蒙 路 47 号 信 XC 内 蒙 古 冯 磊 赤 峰 市 特 种 设 备 检 验 所 内 蒙 古 赤 峰 市 红 山 区 八 里 铺 油 库 路

学习MSP430单片机推荐参考书

3.1 num = 3 ch = 'C' 2

untitled


Microsoft Word - CPE考生使用手冊 docx

PowerPoint Presentation


<4D F736F F D B0EABB79A4E5B8D5C344BBBCB065AAA9>


康體藝術

Ps22Pdf

Microsoft Word - InoTouch Editor编程软件手册 doc


,,,,,,,,,, ( http: \ \ www. ncre. cn,, ) 30,,,,,,,, C : C : : 19 : : : /16 : : 96 : : : ISBN 7

山东建筑大学学分制管理规定(试行)

概述

<4D F736F F D20B9F9B0EABBCDBBAFAB48DEB3B4C1A5BDB3F8A7692E646F63>

ebook15-C

untitled

C语言的应用.PDF

ebook50-11

epub 33-8

C/C++ 语言 - 循环

Microsoft Word 箕æ−¥ï¼‹å®ı稿;

98年度即測即評學科測試與即測即評即發證技術士技能檢定簡章

Microsoft Word - 01.DOC

PowerPoint Presentation

Microsoft Word - 实用案例.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

bingdian001.com

bingdian001.com

untitled

教育部高等学校教学

提问袁小兵:

ISA-9620用户手册.PDF

ebook15-10

<4D F736F F D20C8EDC9E82DCFC2CEE7CCE22D3039C9CF>

OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料


《嵌入式系统设计》教学大纲

C/C++语言 - 分支结构

Java

untitled

CC213

概述

untitled

邏輯分析儀的概念與原理-展示版

目 录 软 件 概 述 软 件 用 途 软 件 运 行 系 统 配 置... 3 使 用 入 门 软 件 登 录 与 退 出 页 面 介 绍... 6 组 别 账 号 编 辑 组 别 编 辑.

創 作 動 機 因 未 成 年 懷 孕 的 案 例 從 國 中 時 期 就 在 身 邊 屢 屢 發 生, 這 意 外 中 的 小 生 命 會 讓 一 個 人 或 說 是 一 對 父 母 的 人 生 產 生 劇 烈 衝 擊, 先 不 談 是 否 成 全 生 命 的 誕 生, 往 往 就 在 社 會 倫

国 内 站 号 AREAID NAMECN DISTRICTCN PROVCN 北 京 北 京 北 京 海 淀 北 京 北 京 朝 阳 北 京 北 京 顺 义 北 京 北 京 怀 柔 北 京 北 京

untitled

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

Transcription:

Memory & Pointer trio@seu.edu.cn

2.1 2.1.1 1 int *p int a 0x00C7 0x00C7 0x00C7 2.1.2 2 int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; 2.1.3 1. 2. 3. 3 int A, *pa, **ppa; pa = &A; ppa = &pa; &ppa ppa *ppa **ppa &pa pa *pa &A A

2.1.4 CPU 8 CPU 1~2 51 1~3 16 CPU 2 MSP430 32 CPU 4 Intel 80386 2.1.5 p int* p; 0x3FF0073D 0x3FF0073D!!! 0x3FF0073D Windows Windows 2.2 1. C 2. 4 : int a[4], *p; p = a; // p =&a[0]; *(a+2) = 0; // a[2] = 0; p[2] = 0; // a[2] = 0;

a 5 int a[4], *p; p = a; a = p; p++; a++; // // // // 2.3 (1). 0 0 0 NULL p = NULL; // NUL NUL \0 p = 0;

(2). (void *) void int n, *p; double *q; void *gp1, *gp2; gp1 = (void *) &n; p = (int *)gp1; 2.4 2.4.1 < > (* < >)(...) int (*func)(void ) func int *func(void) int (*func)(void) int *func(void); // int (*func)(void) //

2.4.2 6 int int fn(int); int (*fp)(int); fp = fn; // fn fp fp = fn(5); // fp fp = & // 1 2 3 2.4.2 1. (polymorphism) 2. (multithreading) API Win32 CreateThread(...pF...) 3. (call-back) (event-driven) Win32 WinProc

2.4.3 7 switch(oper){ case ADD: result=add(op1,op2); break; case SUB: result=sub(op1,op2); break;... } switch double add(double,double); double sub(double,double);... double (*oper_func[])(double,double)={add,sub,...}; 2 switch result=oper_func[oper](op1,op2); oper ASIX Window typedef struct window_class { U8 wndclass_id; STATUS (*create)(char *caption, U32 style, U16 x, U16 y, U16 width, U16 hight, U32 wndid, U32 menu, void **ctrl_str, void *exdata); STATUS (*destroy)(void *ctrl_str); STATUS (*msg_proc)( U32 win_id, U16 asix_msg, U32 lparam, void *data, U16 wparam, void *reserved); STATUS (*msg_trans)(void *ctrl_str, U16 msg_type, U32 areaid, P_U16 data, U32 size, PMSG trans_msg); STATUS (*repaint)(void *ctrl_str, U32 lparam); STATUS (*move)(void *ctrl_str, U16 x, U16 y, U16 width, U16 hight, void *reserved); STATUS (*enable)(void *ctrl_str, U8 enable); STATUS (*caption)(void *ctrl_str, char *caption, void *exdata); STATUS (*information)(void *ctrl_str, struct asix_window *wndinfo); } WNDCLASS;

ASIX Window WNDCLASS WindowClass[] = { {WNDCLASS_WIN, wn_create, wn_destroy, wn_msgproc,wn_msgtrans, wn_repaint, NULL,NULL,wn_caption, NULL}, {WNDCLASS_BUTTON,Btn_create,Btn_destroy,Btn_msg_proc,Btn_msg_trans,Btn_repaint,NULL,Btn_enable,Btn_caption, NULL}, {WNDCLASS_SELECT,sl_create, sl_destroy, sl_msg_proc, sl_msg_trans, sl_repaint,null, sl_enable, sl_caption, NULL}, {WNDCLASS_SELECTCARD,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {WNDCLASS_MENU,menu_create, menu_destroy, menu_msgproc, menu_msgtrans, mn_repaint, NULL, NULL,NULL,NULL}, {WNDCLASS_LIST, Lbox_create, Lbox_destroy, Lbox_msgproc, Lbox_msgtrans, lb_repaint, NULL, NULL,NULL,NULL}, {WNDCLASS_KEYBD, kbd_create,kbd_destroy, kbd_msgproc, kbd_msgtrans, kbd_repaint, NULL, NULL,NULL,NULL}, {WNDCLASS_SCROLL,sb_create, sb_destroy, sb_msgproc, sb_msgtrans, sb_repaint, NULL,sb_enable, NULL,NULL}, {WNDCLASS_KEYBAR,kb_create, kb_destroy, kb_msgproc, kb_msgtrans,null,null, NULL,NULL, NULL}, #ifdef ASIX_DEBUG {WNDCLASS_TEST,tst_create, tst_destroy, tst_msgproc, tst_msgtrans, NULL,NULL,NULL,NULL,NULL} #endif };

char *DoSomething( ) { char i[32*1024]; memset(i,0,32*1024); return i; { 1 2 void DoSomething( ) { int i; int j; int k; memset(&k,0,3*sizeof(int) ); 3 1 { I,j,k 2 I, j, k ( ( ) 3 K K Data Aboart

, Pixle 2 bit Char *buffer; buffer = malloc (x*y/4); Buffer = malloc(x*y/4 + 1);

char *DoSomething( ) { char *p, *q; if ( (p = malloc(1024)) == NULL ) return NULL; if ( (q = malloc(2048)) == NULL ) return NULL; return p; { q p NULL void FreeWindowsTree(windows *Root) { if(root!= NULL) { window *pwnd; /* pwndroot.. */ for(pwnd = Root->Child;pwnd!= NULL;pwnd = pwnd->sibling) FreeWindowTree(pwnd); if(root->strwndtitle!= NULL) FreeMemory(Root->strWndTitle); FreeMemory(Root); } } Pwnd for

struct sizeof Free malloc() ANSI C Free

Mem Free Size 1 8 Free Free Size 7 BASE BASE Allocp Allocp First First 16 Size 1 Size 4 Size 3 BASE BASE Allocp Allocp First First Ptr Free

Allocp First Size 1 Size 4 Size 1 Size 4 Size 1 Size 9 Size 2 Size=3 Size 5

union header { struct { union header *; unsigned long size; } s; char c[8];// For debugging; also ensure size is 8 bytes }; typedef union header HEADER;

struct sheader { struct sheader unsigned long }; *; size; #define ABLKSIZE (sizeof (HEADER)) /* 1*/ #define BTOU(nb) ((((nb) + ABLKSIZE - 1) / ABLKSIZE) + 1)

VC Just Try It