看板Programming
标 题Re: [问题] 有关pointer
发信站政大狂狷年少 (Wed Nov 1 18:01:31 2006)
转信站ptt!ctu-reader!ctu-peer!news.nctu!news.cis.nctu!news.cs.nthu!WHSHS
※ 引述《[email protected] (陷入猫的国度 就当只猫吧)》之铭言:
> 我都是用struct取代二维阵列
> 像是 struct row { int item[10]; }
> 再宣告struct阵列 struct row grids[10];
> 这样在传参数时就很方便...
是很方便没错,
但是就是用起来会比较累一点,
另外,
其实实际的应用程式里,
很少会有机会在 function 内部需要定义固定大小的 2d array,
又还要整个 array pass 出去的,
通常固定大小的 2d array 会是 global variable,
而 function 内部的大都是 (int **) 之类,
被动态配置出来的 2d array,
所以在正式由纯 C 撰写的应用程式里面,
参数都是 pointer 而不是 array,
而 C++ 则是有规定不能以 by value 丢 array,
所以才会想说包成 struct 看看,
但这不单纯是规定和好不好用的问题,
by value 传递大东西本身会让程式比较慢是一大主因。
--
Name: Tseng, Ling-hua E-mail Address:
[email protected]
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Undecided
Homepage:
https://it.muds.net/~uranus
--
╔═══╗ ┼────────────────────────╮
║狂狷 ║ │
* Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮
║ 年少║ ┼╮
< IP:140.119.164.252 > ╰─╮
╚╦═╦╝ ╰
* From:61-230-217-167.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不驯;属於年少的轻狂色彩 ◎
1F:推 u8906250:by value 传递大东西本身会让程式比较慢 163.29.241.8 11/02 13:06
2F:→ u8906250:说的好! 163.29.241.8 11/02 13:07