int (*fp)(int);
ãšèšè¿°ãããš
intã1ã€åŒæ°ã«ãã¡ãintãè¿ãé¢æ°ã®ãã€ã³ã¿å€æ°fpã
宣èšããããšã«ãªããŸããã
typedef int (*fp)(int);
ãšèšè¿°ãããšã
intã1ã€åŒæ°ã«ãã¡ãintãè¿ãé¢æ°ã®ãã€ã³ã¿ååãfpã
ãäœæããããšã«ãªããŸãã
ãã®typedefã®äœ¿çšäŸã¯æ§æäŸå€ãªã®ã§ããããã
決ãæå¥ã ãšèããŠããã°ãããšã¯æãã®ã§ããã
ãŸã解説æžãªã©ã§ã¯ã
typedef int int_array3[3];
ãªã©ã®èšè¿°ã«ã€ããŠã説æãããŠãããã®ãããŸãèŠãããŸããã
K&Rã§ã¯typedefã¯èšæ¶ã¯ã©ã¹æå®åæ±ãã§ãããšã¯
æžããŠãããŸãããããããžãã詳ãã説æããŠãã
æç®ãªã©ãããŸãããæããŠããã ããªãã§ããããã
<2003112217333...@os.rim.or.jp>ã®èšäºã«ãããŠ
ing...@os.rim.or.jpããã¯æžããŸããã
ingram> typedef int (*fp)(int);
ingram> ãšèšè¿°ãããšã
ingram> intã1ã€åŒæ°ã«ãã¡ãintãè¿ãé¢æ°ã®ãã€ã³ã¿ååãfpã
ingram> ãäœæããããšã«ãªããŸãã
ingram>
ingram> ãã®typedefã®äœ¿çšäŸã¯æ§æäŸå€ãªã®ã§ããããã
ingram> 決ãæå¥ã ãšèããŠããã°ãããšã¯æãã®ã§ããã
ã©ã®ãããªæ§æã«å¯ŸããäŸå€ã ãšãèãã§ãããã?
--
åå€å±å€§åŠå€§åŠé¢ æ
å ±ç§åŠç ç©¶ç§ èšç®æ©æ°çç§åŠå°æ»
å°é åç·
In article <2003112217333...@os.rim.or.jp>
Hyu-ga Hiroya <ing...@os.rim.or.jp> writes:
> ããã«ã¡ã¯ããäžè©±ã«ãªããŸãã
> int (*fp)(int);
> ãšèšè¿°ãããš
> intã1ã€åŒæ°ã«ãã¡ãintãè¿ãé¢æ°ã®ãã€ã³ã¿å€æ°fpã
> 宣èšããããšã«ãªããŸããã
> typedef int (*fp)(int);
> ãšèšè¿°ãããšã
> intã1ã€åŒæ°ã«ãã¡ãintãè¿ãé¢æ°ã®ãã€ã³ã¿ååãfpã
> ãäœæããããšã«ãªããŸãã
ã¯ããèšèªã䜿ã£ãŠãã人ã§ãããªããªãæ°ãä»ããªãæã§ãã
ããã²ã
ããããã®èšäºãã¿ãŠãããããããããšã ã£ãã®ããšæã£
ã人ããããããããšæããŸããç§ã typedef ã®è©±ãããæã«ã¯ã
ããŸãå€æ°å®£èšããããµããããŠãé ã« typedef ãä»ãããšåã«
ãªãããšèª¬æããŠããŸãã
> ãã®typedefã®äœ¿çšäŸã¯æ§æäŸå€ãªã®ã§ããããã
äŸå€ãšã¯ãéãã§ãããèšèªã®åœåã®èšèšã«ã¯ãtypedef ããªã
ãŠãå°ã£ãŠããŠãåŸããæ³¥çžåŒã«ä»ã足ãããšããæŽå²ããããŸãã
> K&Rã§ã¯typedefã¯èšæ¶ã¯ã©ã¹æå®åæ±ãã§ãããšã¯
> æžããŠãããŸãããããããžãã詳ãã説æããŠãã
> æç®ãªã©ãããŸãããæããŠããã ããªãã§ããããã
typedef ã¯ãæããã«èšæ¶ã¯ã©ã¹æå®å(staticãšãautoãšã
registerãšã)ã§ã¯ãªãã§ãããã ãã³ã³ãã€ã©ãäœãæã®éœåäžã
äœãå
¥ããªããšãããªããšæã£ãŠã©ããããããšèããŠããæ§æäž
ã¯èšæ¶ã¯ã©ã¹æå®åå
¥ããŠããŸãããšå
¥ãã¡ãã£ããã ãšæããŸãã
äžçš®ã®ææããšãèšããŸãããä»ã«å
¥ããäœå°ãå°ãªãã£ãã®ã§ãããã
> ãŸã解説æžãªã©ã§ã¯ã
> typedef int int_array3[3];
> ãªã©ã®èšè¿°ã«ã€ããŠã説æãããŠãããã®ãããŸãèŠãããŸããã
ãã³ããåããã«ããæã§ããã€ãŸãã解説æžãæžã人ãå®ã¯ãã
ããã£ãŠããªããã説æãããšé¢åãªã®ã§æžããŠããªããšãããã
ããäºæ
ã¯ãããšæããŸãã
ãæ°åãéãïŒãããããããããïŒã
ãç波倧åŠãé»åã»æ
å ±ããããããã
In article <YAS.03No...@kirk.is.tsukuba.ac.jp>, y...@is.tsukuba.ac.jp (Yasushi Shinjo) writes
> ããŸãå€æ°å®£èšããããµããããŠãé ã« typedef ãä»ãããšåã«
> ãªãããšèª¬æããŠããŸãã
cast ããã¯typedefãåãããããã§ãããã
typedef int function();
ã®æ¹ãã
(int ())function
ããã¯èªç¶ãªããã ãã...
> äŸå€ãšã¯ãéãã§ãããèšèªã®åœåã®èšèšã«ã¯ãtypedef ããªã
> ãŠãå°ã£ãŠããŠãåŸããæ³¥çžåŒã«ä»ã足ãããšããæŽå²ããããŸãã
ãããã«ãã¡ãã£ãšã ããããããã€ã³ã¿ãç¡ããã°ãããªããšã
ãæ°ãããããå®éãJava ãšãã«ã¯ç¡ããŠãå°ããªãããã ãã
---
Shinji KONO @ Information Engineering, University of the Ryukyus,
æ²³éçæ²» @ çç倧åŠå·¥åŠéšæ
å ±å·¥åŠç§,
On Mon, 24 Nov 2003 13:47:44 +0900
ta...@hirata.nuee.nagoya-u.ac.jp (Takao Ono) wrote:
> ã©ã®ãããªæ§æã«å¯ŸããäŸå€ã ãšãèãã§ãããã?
æ®éã®ãã€ã³ã¿ã®å®£èšæ§æã«å¯ŸããŠã
é¢æ°ãžã®ãã€ã³ã¿ã®å®£èšæ§æãäŸå€ã®ããã«æããŸããã
ïŒäŸå€ãšããããã¯å¥ç©ã§ãããšããèªèãªã®ã§ãããããïŒ
åãæåã« <2003112217333...@os.rim.or.jp> ã®èšäºã§æžãã
typedefã¯ããŸãé¢ä¿ãªãã£ããããããŸããã
ãããããªãã§ãã®ãããªçåãæ±ããããšãããš
ããããã°ã©ã ã®äžã§
typedef int (*fp)(int);
ã®ãããªãé¢æ°ãžã®ãã€ã³ã¿ã®ååãäœæããŠãéšåãèŠãŠã
ãã®ãããªtypedefã®äœ¿ãæ¹ãç¥ããªãã£ããã調ã¹å§ããäžã§åºãŠãããã®
ãªã®ã§ããããã
typedefã®äœ¿ãæ¹ãšããŠã¯ã
typedef åå æ°åå;
ãšããã®ããŸãåºæ¬ã«ãããšæããŸãã
ãã®çšåºŠãªãã·ã³ãã«ã§ããããããã®ã§ããã
# ãšãããããã ãã®æ©èœã§ããã°#defineã§äºè¶³ããŠããŸããŸãã
äžã®ããååããšå矩èªã§ãããæ°ååããäœæãããšããèªèããã£ããšã
typedef int (*fp)(int);
ã®ãããªèšè¿°ã§æ··ä¹±ãçããŠããŸããŸããã
æ¬åœã¯æåã
typedef int (*fp)(int);
ãšããèšè¿°ã¯
# intã1ã€åŒæ°ã«ãã¡intãè¿ãé¢æ°ãžã®ãã€ã³ã¿ååfpãäœæãããšãã
ã€ã¡ãŒãžã§ã
typedef int(*)(int) fp;
ãšãã
typedef int *int_ptr;
ã®ãããªèšè¿°ã«ãªãããªãã
typedef int()(int) *fp;
èŠãããªæãã§èšè¿°ãããæ°æã¡ã§ãããïŒã¡ãã£ãšç¡çããã§ãããïŒ
ããããèããã®ã§ããã次ã®ããã«èãããšç解ãèŠãããªãã®ã§ã¯ãªãã
ãšåæã«çµè«ä»ããŠããŸããŸãããïŒããããééã£ãŠãããããããŸããããïŒ
é¢æ°ãžã®ãã€ã³ã¿ã¯ã
æ®éã®ãã€ã³ã¿ãšåããããªãå€æ°ãçãªã€ã¡ãŒãžã§ã¯ãªãã
é¢æ°ã®ã¹ã¿ãŒãäœçœ®ïŒã¢ãã¬ã¹ïŒã®å€æŽãå¯èœãªé¢æ°ãããã¿ã€ã宣èšã®
ã€ã¡ãŒãžã§ããã
# ã¹ã¿ãŒãäœçœ®ãå€æŽå¯èœã§ãããããé¢æ°å®çŸ©ãååšããªãã
# ãŸã巊蟺å€ã«ãªãåŸã
æ®éã®é¢æ°ãããã¿ã€ã宣èšãš
ã¹ã¿ãŒãäœçœ®ïŒã¢ãã¬ã¹ïŒå€æŽå¯èœãªé¢æ°ã®ãããã¿ã€ã宣èš
ã®èšè¿°ã®éãã¯ãé¢æ°åã®åã«ã*ããã€ãããã€ããªããã§
åºå¥ãããïŒæŒç®ååªå
é äœã®é¢ä¿ã§â()âãå¿
èŠïŒ
ãã®ãããã¿ã€ã宣èšã®åã«typedefãã€ãããšãããïŒ
ããã§ããããããªããªã£ãŠããŸããŸããã
ãããã調ã¹ãã®ã§ããã
typedef int F(int);
ãªããŠã®ãæ§æçã«ã¯æ£ããããã§ãããããããã¯é¢æ°å®çŸ©æ±ãã«ãªãããã§ãã
ãããã§ã«å¥ã®è©±ã«ãªã£ãŠããŸããŸããã
å
·äœçãªããã®typedefã®çšäŸãªãããç¥ãããã®ã§ããã
æç®çããã°æããŠããã ããŸããã§ããããã
In article <2003112421444...@os.rim.or.jp>, Hyu-ga Hiroya <ing...@os.rim.or.jp> writes
> æ®éã®ãã€ã³ã¿ãšåããããªãå€æ°ãçãªã€ã¡ãŒãžã§ã¯ãªãã
> é¢æ°ã®ã¹ã¿ãŒãäœçœ®ïŒã¢ãã¬ã¹ïŒã®å€æŽãå¯èœãªé¢æ°ãããã¿ã€ã宣èšã®
> ã€ã¡ãŒãžã§ããã
ã€ããïœ
int a;
int *f();
char *c[];
ãšãããa ãšãf ãšã c ãšããååã®ã®å®äœãšåãå®çŸ©ããŠããããã§ããã©ã
ããã«ãtypedef ãã€ãããš...
typedef int a;
typedef int *f();
typedef char *array[];
èŠãç®ãã®ãŸããŸã察å¿ããååã«åãçµã³ã€ããããããã§ãããã
ãªããšãªãã
> typedefã®äœ¿ãæ¹ãšããŠã¯ã
> typedef åå æ°åå;
> ãšããã®ããŸãåºæ¬ã«ãããšæããŸãã
ã£ãŠèããããªããã©ãéããã ããã
typedef å®çŸ©åŒ
ã§ããããã³ã³ãã€ã©ã®å®è£ ãèãããšã
typedef ãåºãŠæ¥ãããmode ã tyedef ã«ããŠã
ãã®ãŸãŸãæ®éã«æ§æ解æããŠã
identifier ãæ¥ãããå€æ°ãšããå®çŸ©ãããããã«ã
ä»ã®åãããã®ååã«å®çŸ©ãã
ã£ãŠããã§ãç°¡åãªãã§ããããå®éãåãæ§æ解æããã°ã©ã 䜿ãããã
ã¹ãã¬ãŒãžã¯ã©ã¹ãããªããšããã£ãŠã人ããããã©ãå®è£
çã«ã¯ã
ã¹ãã¬ãŒãžã¯ã©ã¹ãšåãéšåã«å®è£
ããŸãã
ã ããã
typedef struct hoge {...} hoge,*hogeptr;
ãšãã®äžŠåã®typedefãã
typedef å hoge,*hogeptr;
ã£ãŠããã¯ã
struct hoge {...} hoge,*hogeptr;
ãšåãååã®å®çŸ©åŒãªãã ããªã
> typedef int()(int) *fp;
> èŠãããªæãã§èšè¿°ãããæ°æã¡ã§ãããïŒã¡ãã£ãšç¡çããã§ãããïŒ
ãã® C ã®identifieræãã®ååã£ãŠãããããããããã§ãããã
ãªã®ã§ãããã解決ããããã« typedef ãå°å
¥ããã®ã ãšæããŸãã
(int (*)())(*)()
ãªããŠãäœããªãã ããããããã®ãæžããã...
typedef int (*fnptr)();
typedef fnptr (*fnptr_fn)();
ã ã£ããããŸã ããªããèš±ããã£ã€ãã...
> å
·äœçãªããã®typedefã®çšäŸãªãããç¥ãããã®ã§ããã
> æç®çããã°æããŠããã ããŸããã§ããããã
ãã£ã±ãèŠæ Œæžãªããããªãããªãã åã¯ãK&R ã®åŸã¯ã
ããããªãœãŒã¹ãèªãã§å匷ããŸããã
In article <3989208...@insigna.ie.u-ryukyu.ac.jp>
ko...@ie.u-ryukyu.ac.jp (Shinji KONO) writes:
> cast ããã¯typedefãåãããããã§ãããã
> typedef int function();
> ã®æ¹ãã
> (int ())function
> ããã¯èªç¶ãªããã ãã...
é¢æ°ã®ãã€ã³ã¿ãå
¥ã£ãŠããŸããšãtypedef ã¯å¿
é ã§ãããã
typedef ãªãã§ã¯ã人ã®ç¥æµãè¶ããŠããŸããŸãã
> > äŸå€ãšã¯ãéãã§ãããèšèªã®åœåã®èšèšã«ã¯ãtypedef ããªã
> > ãŠãå°ã£ãŠããŠãåŸããæ³¥çžåŒã«ä»ã足ãããšããæŽå²ããããŸãã
> ãããã«ãã¡ãã£ãšã ããããããã€ã³ã¿ãç¡ããã°ãããªããšã
> ãæ°ãããããå®éãJava ãšãã«ã¯ç¡ããŠãå°ããªãããã ãã
æ§é äœã§ãs.x ãš s->x ã®éããæžããªããªããã ãã©ãå°ã人ã¯
ä»ãå°æ°æŽŸãšãã話ã¯ãããã§ãããã
In article <3989209...@insigna.ie.u-ryukyu.ac.jp>
ko...@ie.u-ryukyu.ac.jp (Shinji KONO) writes:
> ã€ããïœ
> int a;
> int *f();
> char *c[];
> ãšãããa ãšãf ãšã c ãšããååã®ã®å®äœãšåãå®çŸ©ããŠããããã§ããã©ã
ã®é£ããæã¯ãååã«ããããŠä¿®é£Ÿèªãåã«ãåŸã«ã眮ãããšã
ãããšã§ããåã«çœ®ãã®ã¯ãã*ããåŸãã«çœ®ãã®ã¯ãã[]ããšã
ã()ããPascal ã¯åŸãã«ãã眮ããªãããçŽãã¯ãªãããã©ã
ã¯åã«ãåŸãã«ããããŠãã©ã¡ãã®çµåã匷ããããããªããªãã
ãã§ããããšãã°ãäžã®ïŒã€ã®ãã¡ãïŒã€ã¯åããªãã§ããã©ãã©
ãã ãããããŸããã
int *f();
int (*f)();
int *(f());
é¢æ°ã®æ¬åŒ§ãšçµåã©ã®æ¬åŒ§ãæ··ãã£ãŠããã®ã§ãããã«ãã¡ããã¡ã
ãªãã ãã©ã次ã®æ¹ããŸã åªããããªã
char *c[];
char (*c)[];
char *(c[]);
> (int (*)())(*)()
> ãªããŠãäœããªãã ããããããã®ãæžããã...
> typedef int (*fnptr)();
> typedef fnptr (*fnptr_fn)();
> ã ã£ããããŸã ããªããèš±ããã£ã€ãã...
ïŒåã ããªãããŸã ãäžåºŠå€å®£èšããããªãããŠãå€æ°ã®ååãæ¶
ãã°ãããã©ãïŒåã«ãªããšé§ç®ã§ããããšãã°ãint (*fnptr)()
ã«å
šäœã«æ¬åŒ§ãã€ããŠãååãæ¶ããš(int (*)())ãšãªããŸãã
> > å
·äœçãªããã®typedefã®çšäŸãªãããç¥ãããã®ã§ããã
> > æç®çããã°æããŠããã ããŸããã§ããããã
>
> ãã£ã±ãèŠæ Œæžãªããããªãããªãã åã¯ãK&R ã®åŸã¯ã
> ããããªãœãŒã¹ãèªãã§å匷ããŸããã
ã®èŠæ Œæžã£ãŠããŸãšããªãã®ã¯ãããã§ãããèŠæ Œæžãé·ãéãª
ããŠããïŒïŒ²ã®äŸé¡ãå
šéšéããã¿ãããªèšè¿°ããããŸããã
Unix ã® Portable C compiler ã®ããã³ããšã³ãããã®ãŸãŸäœ¿ãã°
ãã®ç¹ã§ã¯äºææ§ã®åé¡ã¯ãªããŠãããªã«å°ããªãã£ããšãã話ã
ãããã
<YAS.03No...@kirk.is.tsukuba.ac.jp>ã®èšäºã«ãããŠ
y...@is.tsukuba.ac.jpããã¯æžããŸããã
yas> ã®èŠæ Œæžã£ãŠããŸãšããªãã®ã¯ãããã§ããã
10幎以äžãåã« ISO ã§èŠæ Œã«ãªã£ãŠããã§ããã©, ãããããŸãšãããã
ãªããšãããšäœããã£ãŠããŸãšãããšåŒã¹ã°ããã®ã....
--
åå€å±å€§åŠå€§åŠé¢ æ
å ±ç§åŠç ç©¶ç§ èšç®æ©æ°çç§åŠå°æ»
å°é åç·
P.S.
æ¥æ¬ãªã JIS ã䜿ãã®ããã¹ãã ãšæãã®ã ã, ãªãããANSI Cããšæž
ããã.
ãããããªãäºãèãããã§ãããäžã®ã¯ã
(int (*)())(*)()
ãš
typedef int (*fnptr)();
typedef fnptr (*fnptr_fn)();
ã¯ãåãããšã§ããããšèšã£ãå
容ãªã®ã§ããããããããšããäž¡è
ã¯äœã®é¢ä¿ããª
ããåãªãtypedefã®çšæ³ã説æãããã®ãªã®ã§ããããã
--
******************************
keizi kounoike
******************************
ããŒã®ãããããããã®ã¯
(int (*)())(*)()
ãšãããã£ã¹ãã䜿ãããã¯
typedef int (*fnptr)();
typedef fnptr (*fnptr_fn)();
ãšå®£èšããŠãããŠ
(fnptr_fn)
ã䜿ãã®ã§ããã°ããŸã ããªããèš±ããããšããããšã§
ãããããã®2ã€ã®ãã£ã¹ãã¯åãã§ãã
(int (*)())(*)()
ã«ãã£ãŠãã£ã¹ããããå ã®åã¯
[1] intãè¿ãé¢æ°ãžã®ãã€ã³ã¿ â (int (*)())
[2] âŠ[1]âŠãè¿ãé¢æ°ãžã®ãã€ã³ã¿ â (âŠ[1]âŠ)(*)()
ã«ãªããŸããtypedefã䜿ãããšã§ã(1)ãšæžããšããã§
ã¯ãããã«fnptrãšæžãã(2)ãšæžããšããã§ã¯fnptr_fn
ãšæžããããã§ããã
--
倪ç°çŽ(Junn Ohta) (æ ª)ãªã³ãŒ/æ°æšªæµäºæ¥æ
oh...@sdg.mdd.ricoh.co.jp
On 25 Nov 2003 16:54:29 GMT
y...@is.tsukuba.ac.jp (Yasushi Shinjo) wrote:
> ããšãã°ãäžã®ïŒã€ã®ãã¡ãïŒã€ã¯åããªãã§ããã©ãã©
> ãã ãããããŸããã
>
> int *f();
> int (*f)();
> int *(f());
intãžã®ãã€ã³ã¿ãè¿ãé¢æ°fã®ãããã¿ã€ã宣èš
int *f();
int *(f());
intãè¿ãé¢æ°ãžã®ãã€ã³ã¿fã®å®£èš
int (*f)();
ã§ããããã
ããããé¢æ°ãã€ã³ã¿ã®ããšã調ã¹ãçŽåŸã ã£ãã®ã§ãã£ã¡ã¯ãããªã
ããããŸããããäžã®ã»ããããããŸããã§ããã
> é¢æ°ã®æ¬åŒ§ãšçµåã©ã®æ¬åŒ§ãæ··ãã£ãŠããã®ã§ãããã«ãã¡ããã¡ã
> ãªãã ãã©ã次ã®æ¹ããŸã åªããããªã
>
> char *c[];
> char (*c)[];
> char *(c[]);
調ã¹ããšããã
charãžã®ãã€ã³ã¿ã5ã€æ ŒçŽã§ããé
åcã®å®£èš
char *c[5];
char *(c[5]);
charã5ã€æ ŒçŽã§ããé
åãžã®ããã€ã³ã¿cã®å®£èš
char (*c)[5];
ã§ããããã
char (*c)[5];
char c5[5] = {'a', 'b', 'c', 'd', '\0'};
char c6[6] = {'1', '2', '3', '4', '5', '\0'};
c = &c5;
ã¯æ£ããã§ããã
c = &c6;
ã¯ã§ããŸãããã
c = c5;
ãã§ããªãã§ããã
é
åã®å
é èŠçŽ ã®ã¢ãã¬ã¹ãšã
é
åãã®ãã®ã®ã¢ãã¬ã¹ïŒïŒïŒã¯éããã®ã¿ããã§ããã
ããŸãã¡ããããããªãã§ãã
å€æ¬¡å é åïŒé åã®é å...ïŒïŒãšé¢ä¿ãããããªæ°ãããŸããã
ãã¯ãããããæå³ã§ããããfnptr_fnã®å Žåã¯ç解ã§ããã®ã§ãããããäžæ¹ã®
(int (*)())(*)()ã®æ¹ã®äœ¿ãæ¹ãã©ããããåãããŸãããç§ã®ããæ¹ããŸããïŒç
解ã§ããŠããªãïŒã®ã ãšæããŸãããã©ãããŠãã³ã³ãã€ã©ãŒãåãä»ããŠãããŸã
ããã©ããã颚ã«äœ¿çšããã®ãæããŠé ããã°å¹žãã§ãã
ãããªãµãã§ããããã...
int (*(*ptr1)())();
char *(*ptr2)();
ptr1 = ((int (*)())(*)())ptr2;
ãšãæã£ããã ãã§ããããã? (^^;
å匷ããªãããŠããŸãã(^^;
In article <2003112623504...@os.rim.or.jp>
Hyu-ga Hiroya <ing...@os.rim.or.jp> writes:
> > ããšãã°ãäžã®ïŒã€ã®ãã¡ãïŒã€ã¯åããªãã§ããã©ãã©
> > ãã ãããããŸããã
> > int *f();
> > int (*f)();
> > int *(f());
> intãžã®ãã€ã³ã¿ãè¿ãé¢æ°fã®ãããã¿ã€ã宣èš
> int *f();
> int *(f());
>
> intãè¿ãé¢æ°ãžã®ãã€ã³ã¿fã®å®£èš
> int (*f)();
> ã§ããããã
ã¯ããçµå±ãf ãšããååã«ã* ãš () ã®ïŒã€ãå·Šå³ããä»ããæ
* ã«ã¯ãå³ã® () ã®æ¹ãçµå床ã匷ããšããããšã§ãã
> > é¢æ°ã®æ¬åŒ§ãšçµåã©ã®æ¬åŒ§ãæ··ãã£ãŠããã®ã§ãããã«ãã¡ããã¡ã
> > ãªãã ãã©ã次ã®æ¹ããŸã åªããããªã
> > char *c[];
> > char (*c)[];
> > char *(c[]);
ãããåãã§ãããçµå床ãšããæå³ã§ã¯ãf ãšããååã«ã* ãš
[] ã®ïŒã€ãå·Šå³ããä»ããæ * ã«ã¯ãå³ã® [] ã®æ¹ãçµå床ã匷
ããšããããšã§ãã
> char (*c)[5];
> char c5[5] = {'a', 'b', 'c', 'd', '\0'};
> char c6[6] = {'1', '2', '3', '4', '5', '\0'};
> c = &c5;
> ã¯æ£ããã§ããã
> c = &c6;
> ã¯ã§ããŸãããã
> c = c5;
> ãã§ããªãã§ããã
ãã®å Žåãé åã®èŠçŽ æ°ãŸã§èŠãŠãšã©ãŒãã§ãã¯ãããã§ããã£ãïŒ
ããšãcdecl ãšããããã°ã©ã ããã£ãŠãè±èªã§èª¬æããŠãããŸãã
------------------------------------------------------------
% ./cdecl
Type `help' or `?' for help
cdecl> explain char *c[];
declare c as array of pointer to char
cdecl> explain char (*c)[];
declare c as pointer to array of char
cdecl> explain char *(c[]);
declare c as array of pointer to char
cdecl>
cdecl> explain int *f();
declare f as function returning pointer to int
cdecl> explain int (*f)();
declare f as pointer to function returning int
cdecl> explain int *(f());
declare f as function returning pointer to int
cdecl>
------------------------------------------------------------
cdecl ããæ¥æ¬èªïŒéããŒã©ã³ãïŒãã®ãããããšãçµåã«é¢ããŠ
ã¯ãã£ãšåããããããšæããã ãã©ãã©ããã«ãªãã§ãããã
char (*c)[5]ãšc5ãc6ã§ã¯åãéãã®ã§ãc = c5ãc = &c6ãããŸãè¡ããªãã®ã¯åœ
ç¶ã®ãããªæ°ãããŸãã
åçŽãªã±ãŒã¹ãšããŠ
char * cc;
char c5[5] = {'a', 'b', 'c', 'd', '\0'};
ãšããå Žåã
cc = &c5; //ééã
cc = &c5[0]; //æ£ãã
cc = c5; //æ£ãã
ã«ãªããšæããŸãã&c5[0]ãšc5ã¯ãåãæå³ã§ããã&c5ã¯éãåãæãããã§ãã»
ã»ããªã
äžã®äŸã®
char (*c)[5];
char c5[5] = {'a', 'b', 'c', 'd', '\0'};
å Žåã§ã
c = &c5;
ãšããæãcãçšããŠãc5[]ã®äžèº«ã® 'a', 'b', 'c', 'd'ãïŒã€ãã€è¡šç€ºããã«ã¯ã
ã©ãããã°ãããèããã°ãã®éããåããããã«ãªã®ã§ã¯ãšæããŸããã
In article <bq71cp$nhf$1...@news511.nifty.com>
<koun...@mbh.nifty.com> writes:
> åçŽãªã±ãŒã¹ãšããŠ
> char * cc;
> char c5[5] = {'a', 'b', 'c', 'd', '\0'};
> ãšããå Žåã
> cc = &c5; //ééã
> cc = &c5[0]; //æ£ãã
> cc = c5; //æ£ãã
> ã«ãªããšæããŸãã&c5[0]ãšc5ã¯ãåãæå³ã§ããã&c5ã¯éãåãæãããã§ãã»
> ã»ããªã
ã©ãããªãã
ç§ã®æèŠã ãšããé
åã®ååã ãæžãããå
é èŠçŽ ã®ãã€ã³ã¿ã«ãª
ãããšããä»æ§ã¯ãä»æ§ã®ãã°ã ãšæããŸããæŽå²çã«ãé
åã®ã
ãã«ïŒæ®éã¯ïŒå€§ããã¡ã¢ãªã®ã³ããŒãçŠæ¢ãããã£ããšããã®ã¯ã
ããããŸããããšãã°ãé¢æ°åŒåºãã®æã«
------------------------------------------------------------
char c5[5];
f( c5 );
------------------------------------------------------------
ãšæžããšãé
åå
šäœã§ã¯ãªããŠãã®å
é çªå°ïŒãã€ã³ã¿ïŒãéãã
ãŸãããããããããæ¬åœã¯ã
f( &c5 );
ãšæžãããã«ããæ¹ãããã£ããšæããŸããããã§ãf( c5 ) ãæ
å³ãšããŠçŠæ¢ãããšã
æ§é äœãæåã¯ä»£å
¥ãã§ããªããã°ãåŒæ°ã§æž¡ãã®ãã§ããªãã£ã
ã§ããããé
åãæ§é äœãšåãæ±ãã«ããã°è¯ãã£ããšæããŸãã
> äžã®äŸã®
> char (*c)[5];
> char c5[5] = {'a', 'b', 'c', 'd', '\0'};
> å Žåã§ã
> c = &c5;
> ãšããæãcãçšããŠãc5[]ã®äžèº«ã® 'a', 'b', 'c', 'd'ãïŒã€ãã€è¡šç€ºããã«ã¯ã
> ã©ãããã°ãããèããã°ãã®éããåããããã«ãªã®ã§ã¯ãšæããŸããã
ããèšãããŠãããåãããŸãããä»ã®ïŒ£ã³ã³ãã€ã©ã¯ãc5 ã
&c5 ãåãå€ã«ãªããŸãã
------------------------------------------------------------
% gcc -v
Using builtin specs.
gcc version 2.95.2 19991024 (release)
% cat array-c5.c
main()
{
char c5[5];
printf("%d, %d\n",c5,&c5);
}
% gcc array-c5.c
% ./a.out
-4262664, -4262664
%
------------------------------------------------------------
ãããã話ãªã®ã§ã¯?
% gcc -v
Reading specs from /usr/local/GNU/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
% cat array-c5.c
main()
{
char c5[5];
printf("%d, %d\n",sizeof(c5),sizeof(&c5));
}
% gcc array-c5.c
% ./a.out
5, 4
%
ã©ããã§ããæ°åããã®ããã«å€§åŠã§å
端çãªç 究ããããŠããæ¹ïŒããã¯ã以åè«
æçãããã§çŽ¹ä»ãããã®ãã¡ãã£ãšèŠããã®ã§ããããŸããããã³ãã³ã«ã³ãã³ã§
ããã®ã§ããããã¬ãã«ãéãããšæã£ãããã§ããïŒãšããåãåºæ¥ãã»ã©ã®ç¥è
ãçŽ é€ãæã¡åãããŠããªãã®ã§ãåèãšããŠèªãŸããŠé ããŸããå
šãã®ãŽãèšäºã§
ãããããããã³ã¡ã³ãããããã®ã§ãäœããªããã©ãããšèšãããšã§ã
In article <bq7c4h$kgm$1...@ns.src.ricoh.co.jp>
oh...@src.ricoh.co.jp (Junn Ohta) writes:
> ãããã話ãªã®ã§ã¯?
> main()
> {
> char c5[5];
> printf("%d, %d\n",sizeof(c5),sizeof(&c5));
> }
> % gcc array-c5.c
> % ./a.out
> 5, 4
> %
sizeof() ã¯ã話ãå¥ã§ããããæ®éã¯ãsizeof() ã«ã¯åã®åå
(struct ãªããããå«ã)ããå€æ°åãæžãããããªãã§ãããå€
æ°åã§ããªãååã§ããªã &c5 ã®ãããªåŒãæžãã®ã¯ãå€ãªæã
ãããŸãã*ãªããããã©ã
ãã¡ã®è¥ããã®ã§ãããsizeof() ã§é
åã®å€§ãããåãããšæã£
ãŠããã°ã©ã ãæžãããããŸããé
åãã³ããŒãããæã«ã
sizeof() ããŠãmalloc() ãã¡ãããã§ãããã
q = malloc( sizeof(*p) );
memcpy( q, p, sizeof(*p) );
ããããp ãé
åã§ã¯ãªããŠãæ§é äœãšãåãªã int ã®ãã€ã³ã¿
ãªããããã ããã©ãé
åã§ã¯ãã¡ã§ãããªããã¡ããé£ããã¿ã
ããããŸã説æã®ä»æ¹ã¯ããªãã§ããããããsizeof() ã¯ã³ã³ã
ã€ã©ã解éããããšããã£ãŠãããªããªãéããªãããšããããŸãã
å¿
èŠãªã¡ã¢ãªã®ãã€ãæ°ãè¿ãéæ³ã®é¢æ°ã ãšæã£ãŠããã¿ããã
é
åã«ã & ãä»ããŠãã€ã³ã¿ã«ããæ¹æ³ãªãã説æãå°ãã¯æ¥œã ã£
ããããªæ°ããããã©ã
> ç§ã®æèŠã ãšããé
åã®ååã ãæžãããå
é èŠçŽ ã®ãã€ã³ã¿ã«ãª
> ãããšããä»æ§ã¯ãä»æ§ã®ãã°ã ãšæããŸãã
ãããããªãã®æèŠããã°ã£ãŠãããã§ãããã
> char c5[5];
> f( c5 );
> ãšæžããšãé
åå
šäœã§ã¯ãªããŠãã®å
é çªå°ïŒãã€ã³ã¿ïŒãéãã
> ãŸãããããããããæ¬åœã¯ã
> f( &c5 );
> ãšæžãããã«ããæ¹ãããã£ããšæããŸããããã§ãf( c5 ) ãæ
> å³ãšããŠçŠæ¢ãããšã
ããã
char c; c = c5[0];
ã¯çŠæ¢ã§
char c; c = (&c5)[0];
ã§ããïœïœïœ
ç¥ç°æåº <ca...@kgc.co.jp>
ã件ã®typedefãšåãåã«ãªãã®ã
> int (*(*ptr1)())();
ãªã®ã§ã
> ptr1 = ((int (*)())(*)())ptr2;
ããããã£ã¹ãããåãéã£ãŠãŸãããã(^^;
ïŒ ptr1 = (int (*(*)())())ptr2;
ã(int (*)())(*)()ãã ãšã(*)() ã int (*)() ã§
ãã£ã¹ãããããšããŠããã®ã§ãïŒ
ããããc5 ãšæžããšãé
åå
šäœããæå³ããããã«ããããšãã
æå³ã§ããå¥ã«é¢æ°åŒåºãã§é
åå
šäœãæž¡ãããšãèš±å¯ããŠããã
ããã©ã
Pascal ãšããããã°ã©ãã³ã°èšèªã§ã¯ããããªã£ãŠããŸããé
å
ã®é·ããéããšåãéããšãã£ãŠéããªããšããèŠæ Œã®ããã°ã©ã
ã³ã°èšèªããããã«ããã¯ãªãã§ããããšããããšã§ãé
åã®é·ã
ãéãã®ã¯ïŒ¯ïŒ«ãšããããšã«ããããšããã³ã³ãã€ã©ããçµæ§ãã
ãŸãããå®çšçãªããã°ã©ã ã§ã¯å¿
é ã®æ©èœã§ããèŠæ Œéåãªãã
ãã©ãã
> char c; c = c5[0];
> ã¯çŠæ¢ã§
ããã¯ããã¡ãã OK ã«ããŸãã
> char c; c = (&c5)[0];
> ã§ããïœïœïœ
ããã¯ãæ§æãšã©ãŒã«ããŸããc5 ã§é
åå
šäœã§ã&c5 ã§ãé
åå
š
äœã®çªå°ãé
åå
šäœã®çªå°ã« [] ãä»ããã®ã¯æå³ããªããšããŸãã
ããã§ã
char c; c = (*(&c5))[0];
ããã¯ãok ã«ããŸãã*&ã§æã¡æ¶ãããã®ã¯ãæ®éã§ãããã
c5 ãé
åã ãããå€ã«æããããããªãããã©ãæ§é äœãªãå¥ã«
æ®éã§ããã
------------------------------------------------------------
struct
{
char c0, c1, c2, c3, c4;
} s5;
char c; c = s5.c0; // ok.
char c; c = (&s5).c0; // syntax error.
char c; c = (*(&s5)).c0;// ok.
------------------------------------------------------------
ãã®æ§é äœã®èãæ¹ãé
åã«ãããšãããªããŸãã
------------------------------------------------------------
char c5[5];
char c; c = c5[0]; // ok.
char c; c = (&c5)[0]; // syntax error.
char c; c = (*(&c5))[0];// ok.
------------------------------------------------------------
èšèªã§ãæ§é äœã®ä»£å
¥ãã§ããããé¢æ°ã®åŒæ°ã§æž¡ããããã«ãªã£
ãã®ã¯ããã€é ã§ããã£ãïŒããã®æãé
åãåãããã«ãã¹ãã ã£
ããã ãšæããŸãã
Yasushi Shinjo wrote:
> ããããc5 ãšæžããšãé
åå
šäœããæå³ããããã«ããããšãã
> æå³ã§ããå¥ã«é¢æ°åŒåºãã§é
åå
šäœãæž¡ãããšãèš±å¯ããŠããã
> ããã©ã
c5ã¯ãããŸã§ããé
åãè¡šãèå¥åã§ãã
ãã ãã»ãšãã©ã®æ§æã§æé»ã®ãã¡ã«å
é èŠçŽ ãžã®ãã€ã³ã¿ã«å€æããããšããããšã§ãã
sizeofãš&ãäŸå€ãä»ã«ãäŸå€ã¯ããããªã
ã ããã&c5[0]ãšc5ã¯ãŸã£ããåãããã§ã¯ãããŸããã
é¢æ°åã䌌ããããªããã§ãããã
--
ãâââââââããããããïŒïŒŒ
ãâ (^^)ïŒ âã ãïŒïŒŒïŒãã
â¡âââââââ¡ ãïŒãïŒããããïŒïŒŒ
ãâ¡ïŒ[]ïŒïŒâ¡ãç岡ãå¿(Kumaoka Shinobu)
ãïŒïŒ IIII ïŒïŒãtito...@jcom.home.ne.jp
ãâ ââââââ ãïŒãããããïŒãããããã
ãâ ãããããâ
ïŒï¿£ïŒŒïŒïŒŒïŒ¿ïŒï¿£ïŒŒïŒïŒŒïŒï¿£ïŒŒïŒï¿£ïŒŒïŒï¿£ï¿£ïŒŒïŒïŒŒïŒ
Followup-To: fj.net.words ã§ãã
2003幎11æ28æ¥(é)20æ07åçºä¿¡ã®
<YAS.03No...@kirk.is.tsukuba.ac.jp>ããªãã¡
"Array and pointer" ãšé¡ããèšäºãã
> ç§ã®æèŠã ãšããé
åã®ååã ãæžãããå
é èŠçŽ ã®ãã€ã³ã¿ã«ãª
> ãããšããä»æ§ã¯ãä»æ§ã®ãã°ã ãšæããŸããæŽå²çã«ãé
åã®ã
> ãã«ïŒæ®éã¯ïŒå€§ããã¡ã¢ãªã®ã³ããŒãçŠæ¢ãããã£ããšããã®ã¯ã
> ããããŸããããšãã°ãé¢æ°åŒåºãã®æã«
ä»æ§ã®äžå
·åã¯ããã°ãã§ã¯ãªããæ¢ããŠè±èªã§è¡šçŸãããªãã°
ããšã©ãŒãã ãšæããã§ãããã©ãã§ããããã
========================================================================
ãã¯ãªã¹ãã¹ãšãããŠã£ã³ã¯æ£ç¢ºã«äžèŽãããã§ããã -- A.Asimov --
--
äžå· æé ( T.Nakagawa ) mailto:yae...@kikansha.jp
http://www.kikansha.jp/~yaemon/
> > char c; c = c5[0];
> > ã¯çŠæ¢ã§
> > char c; c = (&c5)[0];
> > ã§ããïœïœïœ
>
> ããããc5 ãšæžããšãé
åå
šäœããæå³ããããã«ããããšãã
> æå³ã§ãã
c5 ãšæžããšãé
åå
šäœãããŠããšã¯
c5 + 1 ãšæžããšããé
åå
šäœ + 1ãã§ãã??
ã©ãããæå³ã§ã?????
c5 ã®åèŠçŽ ã« 1 ã足ã?
# ããã¯ããã§ç¢ºãã«æçšãã
# c5 * 2 ãã§ãããšãªãè¯ããã
# c5 * c5 ãã§ãããšãã£ãšè¯ããã
ç¥ç°æåº <ca...@kgc.co.jp>
In article <3FC7EEC6...@jcom.home.ne.jp>
Shinobu Kumaoka <tito...@jcom.home.ne.jp> writes:
> ç岡ã§ãã
> c5ã¯ãããŸã§ããé
åãè¡šãèå¥åã§ãã
> ãã ãã»ãšãã©ã®æ§æã§æé»ã®ãã¡ã«å
é èŠçŽ ãžã®ãã€ã³ã¿ã«å€æããããšããããšã§ãã
ãã®ãæé»ãããããŠãæ瀺çã«ã&ããæžãããšãã話ãããŠã
ãããã§ãã
> sizeofãš&ãäŸå€ãä»ã«ãäŸå€ã¯ããããªã
ãã»ãšãã©ããšãäŸå€ããã©ãèãããã
> é¢æ°åã䌌ããããªããã§ãããã
ããã§ãããé¢æ°ãžã®ãã€ã³ã¿ãã* ä»ããæãšä»ããªãæã§åã
åãããããããŠãåããã«ããã§ãã
------------------------------------------------------------
int (*f)();
(*f)( 10 ); // ok.
f( 10 ); // ok. äžãšåãã
------------------------------------------------------------
In article <s7fad6f...@xxx.kgc.co.jp>
ca...@xxx.kgc.co.jp writes:
> c5 ãšæžããšãé
åå
šäœãããŠããšã¯
> c5 + 1 ãšæžããšããé
åå
šäœ + 1ãã§ãã??
ãããã
> ã©ãããæå³ã§ã?????
æ®éã®èšèªã§ã¯ããããªã®æå³ã¯ãªãããããªãã®ããªããã ãã
ãé
åã®åã
ã®èŠçŽ ã«ã+ããšãããªãã¬ãŒã¿ãå¹ããšããä¿èšŒã¯
ãªãããæ§é äœã«ã+ãæŒç®åã¯å¹ããªãã§ããããããªæ©èœãæ§
æã¬ãã«ã§ã³ã³ãã€ã©ã«å
¥ããæ°ã¯ããŸããã
ïŒïŒã§èªåã§å®çŸ©ãã人ã¯ããããããclass ãªãèš±ããŠããã
ãã©ããã㪠class ã¯ãããŸã䜿ããããšã¯æããªãã ãããªãã
ãããïŒïŒã§ããsyntax error ã«ãªãã®ã¯ç¡çãªãã§ããã£ãïŒ
> c5 ã®åèŠçŽ ã« 1 ã足ã?
> # ããã¯ããã§ç¢ºãã«æçšãã
APL ãšããããããæå³ã ã£ãããããããã§ãå€ãªèšèªã¯ããã
ããé
åãšã¹ã«ã©ã®æŒç®ãèšèªæšæºã«ããŠæçšãšã¯æããŸããã
In article <bqa97m$mes$1...@newsserv.ics.es.osaka-u.ac.jp>
SAITOH akinori <sai...@ist.osaka-u.ac.jp> writes:
> 倧éªå€§åŠã®éœè€ã§ã
> é«çŽã¢ã»ã³ãã©æŽŸãããããããšãã=ãã§ãé
åå
šäœã代å
¥
> ã§ããã®ã¯æ¹æª(è€é/CPUãå°ãããšã¯ããœãŒã¹ã³ãŒãã§ã¿ãŠã
> è¡æ°ãå€ããªãããšããååãæ²ããããŠããã)(ç¬ïŒã
çŠæ¢ããŠããããã©ãæ§æã¬ãã«ãšããããã¯ãæå³ã¬ãã«ã§çŠæ¢
ãããããããããªãããšãã話ãããŠããããã§ãã
Linux ã® fork ã®ã³ãŒãã§ãããã»ã¹æ§é äœã *new = *old ã®ã
ãã«ã³ããŒããŠãããã§ããã©ãæåèŠèœãšãã¡ãã£ãŠã
> Cãé«çŽèšèªãšããŠæããã人ã¯å€ä»åŸã絶ããã
CPU ãéããªã£ããããããã«åãããŠèãæ¹ãå€ããŠã¯ã©ããã
ãšãã話ã§ãã
In article <bqaava$n...@utogw.gssm.otsuka.tsukuba.ac.jp>
ku...@gssm.otsuka.tsukuba.ac.jp writes:
> ä¹
éã§ãã
> ã§ãstructã ãš=ã§ä»£å
¥ã§ããããšããã®ãšæŽåæ§ã⊠ä¹
é
å
éšã«é
åãå«ãæ§é äœãã= ã§ä»£å
¥ã§ããã®ã«ãæ§é äœåç¬ãªã
代å
¥ã§ããªããã§ãããä»ã¯ã
ãæ°åãéãïŒãããããããããïŒã
ãç波倧åŠãé»åã»æ
å ±ããããããã
----------------------------------------------------------------------
From sai...@ist.osaka-u.ac.jp Sat, 29 Nov 2003 23:07:21 +0900
From: SAITOH akinori <sai...@ist.osaka-u.ac.jp>
Newsgroups: fj.net.words
Subject: Re: ä»æ§ã®ãã°
Date: Sat, 29 Nov 2003 23:07:21 +0900
Message-ID: <bqa97m$mes$1...@newsserv.ics.es.osaka-u.ac.jp>
倧éªå€§åŠã®éœè€ã§ã
T.P.S.Nakagawa wrote:
> ãã€ãå«ãã®äžå·ãšç³ããŸãã
>> ç§ã®æèŠã ãšããé
åã®ååã ãæžãããå
é èŠçŽ ã®ãã€ã³ã¿ã«ãª
>> ãããšããä»æ§ã¯ãä»æ§ã®ãã°ã ãšæããŸããæŽå²çã«ãé
åã®ã
>> ãã«ïŒæ®éã¯ïŒå€§ããã¡ã¢ãªã®ã³ããŒãçŠæ¢ãããã£ããšããã®ã¯ã
>> ããããŸããããšãã°ãé¢æ°åŒåºãã®æã«
> ä»æ§ã®äžå
·åã¯ããã°ãã§ã¯ãªããæ¢ããŠè±èªã§è¡šçŸãããªãã°
> ããšã©ãŒãã ãšæããã§ãããã©ãã§ããããã
ããªã·ãŒã®éãã§ãããã
Cãé«çŽèšèªãšããŠæããã人ã¯å€ä»åŸã絶ããã
ãããã芳ç¹ããã¯ãã°ã§ãããCã¯é«çŽã¢ã»ã³ãã©ã ãš
èãããªãã°åœç¶ã®ä»æ§ã§ããæè©®å€æ°åã¯ãã±ãŒã·ã§ã³
ã«å¯Ÿããã©ãã«ã®å€çš®ãªã®ã ããã
é«çŽã¢ã»ã³ãã©æŽŸãããããããšãã=ãã§ãé
åå
šäœã代å
¥
ã§ããã®ã¯æ¹æª(è€é/CPUãå°ãããšã¯ããœãŒã¹ã³ãŒãã§ã¿ãŠã
è¡æ°ãå€ããªãããšããååãæ²ããããŠããã)(ç¬ïŒã
éœè€æçŽãsai...@ist.osaka-u.ac.jp
From ku...@gssm.otsuka.tsukuba.ac.jp 29 Nov 2003 14:37:30 GMT
From: ku...@gssm.otsuka.tsukuba.ac.jp
Newsgroups: fj.net.words
Subject: Re: ä»æ§ã®ãã°
Date: 29 Nov 2003 14:37:30 GMT
Message-ID: <bqaava$n...@utogw.gssm.otsuka.tsukuba.ac.jp>
ä¹ éã§ãã
sai...@ist.osaka-u.ac.jpãã:
> é«çŽã¢ã»ã³ãã©æŽŸãããããããšãã=ãã§ãé
åå
šäœã代å
¥
> ã§ããã®ã¯æ¹æª(è€é/CPUãå°ãããšã¯ããœãŒã¹ã³ãŒãã§ã¿ãŠã
> è¡æ°ãå€ããªãããšããååãæ²ããããŠããã)(ç¬ïŒã
ã§ãstructã ãš=ã§ä»£å
¥ã§ããããšããã®ãšæŽåæ§ã⊠ä¹
é
> > c5 ãšæžããšãé
åå
šäœãããŠããšã¯
> > c5 + 1 ãšæžããšããé
åå
šäœ + 1ãã§ãã??
>
> ãããã
>
> > ã©ãããæå³ã§ã?????
>
> æ®éã®èšèªã§ã¯ããããªã®æå³ã¯ãªãããããªãã®ããªãã
c5 + 1 ã«æå³ãç¡ã
ãŠããšã¯
*(c5 + 1)
ã«ã
c5[1]
ã«ãæå³ãç¡ãã®ã§ããã
ç¥ç°æåº <ca...@kgc.co.jp>
> > c5 + 1 ãšæžããšããé åå šäœ + 1ãã§ãã??
> > c5 ã®åèŠçŽ ã« 1 ã足ã?
> > # ããã¯ããã§ç¢ºãã«æçšãã
>
> APL ãšããããããæå³ã ã£ãããããããã§ãå€ãªèšèªã¯ããã
> ãã
å
šç¶é¢ä¿ãããŸãããã
LabVIEW ã§ã¯ããããæå³ã«ãªããŸãã
c5 * 2 ã¯ã¹ã«ã©åã
c5 op c5 ã¯åèŠçŽ å士㮠op (ååæŒç®)ã
LabVIEW ããå€ãªèšèªããšããã®ã¯ã
ãŸãããã®éãã§ãã
ç¥ç°æåº <ca...@kgc.co.jp>
ããããã®æšè«éçšã¯ãç解ããŠããŸããã
c5[1] ã¯ãæå³ããããŸããé
åãªãã ãããé
åã®ïŒçªç®ã®èŠçŽ ã
*(c5 + 1) ã¯ãæå³ããªãã§ãããã
*(&c5[0]+1) ã¯ãæå³ããããšããŠãã
*(c5[0]+1) ã¯ãint ã« * ãä»ããã®ã§ãšã©ãŒã
ãc5[1]ãš*(c5 + 1)ã¯ãæªæ¥æ°žå«ãã©ããªã³ã³ããã¹ãã§ããŸã£ã
ãåãæå³ã§ããããšãã話ã¯ããªãããã§ãã
In article <s7f7k1j...@xxx.kgc.co.jp>
ca...@xxx.kgc.co.jp writes:
> > > c5 + 1 ãšæžããšããé
åå
šäœ + 1ãã§ãã??
> å
šç¶é¢ä¿ãããŸãããã
> LabVIEW ã§ã¯ããããæå³ã«ãªããŸãã
é
åã«æŒç®åã+ããå¹ããªããã®ãå
¥ã£ãŠããããã©ããªããŸã
ãïŒãæ§é äœãšãã
> c5 * 2 ã¯ã¹ã«ã©åã
> c5 op c5 ã¯åèŠçŽ å士㮠op (ååæŒç®)ã
é
åãšé
åã®æŒç®ã¯ããŸãæ®éã ãšæããŸããã¹ã«ã©åã¯ã2 * c5
ã®ããã«æžãæµåã奜ããªãã ãã©ãã©ã£ã¡ãããã¿ããããæ¥æ¬
ã®é«æ ¡ã§ã¯ã2 * c5 ãªãã ãã©ã
çŽåŸã§ããæ²³éãããæããããäŸã¯ãtypedefã䜿çšããçç±ã®ïŒã€ã«ã¯å¯èªæ§ã
ããããããã®ãã®ã§ããããç¡æ¡ä»¶ã«typedefã䜿çšãããšç¡çšãªæ··ä¹±ãèµ·ãããš
ããããäŸã瀺ããããšããããšã§ããã
typedef int (*fnptr)();
typedef fnptr (*fnptr_fn)();
ãããfnptr_fnã®åã¯ãäžèŠãããš (int (*)())(*)()ããã«èŠããŠããŸãããå®é
ã¯int (*(*)())()ã§ãããã ããäžã®å Žåã¯ããµãã€ã®typedefã䜿çšããã®ã§ã¯ãª
ãæåãã
typedef int (*(*fnptr_fn)())();
ãšãã¹ãã§ã¯ãªãããšã
æå(int (*)())(*)()ãèŠããšãã«ããªããéåæãæããŠãŸããããã¯ã£ãããšã
ããããšèšããã»ã©ç¢ºä¿¡ããããŸããã§ããã
char c[5];
char* pc1;
ãšãã£ãå Žåã
pc1 = c;
ãã ãããšããè«çã§ããã®ã¯ãããã®ã§ããã
pc1 = &c;
ãã ããšããããšã«ãªããã§ãããïŒ
ãããèªãããšã
*pc1 ã¯*(&c) ããªãã¡ cãã®ãã®(é
åå
šäœ)ãšããããšã«ãªãã®ã§ã
ãšãããšãé
åãæ±ãããã®ãã€ã³ã¿ã¯åžžã«
char (*pc2)[5];
ã®ããã«å®£èšããªããã°ãªããªããšããããšã«ãªãã®ã§ãããïŒ
åæ§ã«ãpc1[0]ãèšèªä»æ§äžãã£ãŠã¯ãããªãããšããè«çå±éã«
ãªãã®ã§ãããïŒ
ãªãã ããããäžäŸ¿ã«ãªãã ããªããããªãããšããæ°ãããŸããã
--
General Shadow <gene...@mail.goo.ne.jp>
General Shadow wrote:
> ãšãããšãé
åãæ±ãããã®ãã€ã³ã¿ã¯åžžã«
> char (*pc2)[5];
> ã®ããã«å®£èšããªããã°ãªããªããšããããšã«ãªãã®ã§ãããïŒ
ãããããªããŠã
pc1=&c[0];
ãšãæ瀺çã«æžããŸããããšããããšã§ã¯ã
> ãªãã ããããäžäŸ¿ã«ãªãã ããªããããªãããšããæ°ãããŸããã
äžäŸ¿ãšãããããå°ã
é¢åã«ãªãçšåºŠã§ããã
ãã®ä»£ãããé
åã®ã³ããŒãæŒç®ãéåæç¡ãèšè¿°ã§ããã®ãã¡ãªããã§ããããã
æŽå²ã®ifãæ€èšŒããã®ã¯é¢çœãã§ãããåœæã®äºæ
ãç解ã§ããŸããã
ä»ã®ä»æ§ãããã»ã©ãã¡ãªãã®ã ãšãç§ã¯æããŸããã
In article <20031130120626...@mail.goo.ne.jp>
General Shadow <gene...@mail.goo.ne.jp> writes:
> char c[5];
> char* pc1;
> pc1 = &c;
> ãã ããšããããšã«ãªããã§ãããïŒ
ã¯ãããã®ãŸãŸã§ã¯ãã¡ããã£ã¹ããããã°èš±ããŠãããããããª
ãããªã
pc1 = (char *)&c ;
é
åå
šäœã®çªå°ã¯ãé
åã®å
é ã®èŠçŽ ã®çªå°ãšå€ãšããŠã¯åããšã
ãããšã§ã
> ãšãããšãé
åãæ±ãããã®ãã€ã³ã¿ã¯åžžã«
> char (*pc2)[5];
> ã®ããã«å®£èšããªããã°ãªããªããšããããšã«ãªãã®ã§ãããïŒ
é
åãžã®ãã€ã³ã¿ãšé
åã®èŠçŽ ãžã®ãã€ã³ã¿ã¯å¥ç©ã§ãã
æ§é äœãžã®ãã€ã³ã¿ãšæ§é äœã®èŠçŽ ãžã®ãã€ã³ã¿ãå¥ç©ã®ããã«ã
ãé
åãæ±ãããã®ãã€ã³ã¿ãã£ãŠãã©ã¡ãã§ããïŒ
æ§é äœã®å Žåã¯ããããªæãã
struct
{
char c0,c1,c2,c3,c4;
} s5 ;
pc1 = (char *)&s5 ;
pc1 = &s5.c0 ;
> åæ§ã«ãpc1[0]ãèšèªä»æ§äžãã£ãŠã¯ãããªãããšããè«çå±éã«
> ãªãã®ã§ãããïŒ
ãããããã㯠ok ã§ããããããªãã§ããã
int i;
c = *(pc1+i); // ok.
c = pc1[i]; // ok. äžãšåãæå³ã
ã€ãŸãããã€ã³ã¿å€æ°ããã£ãæã«ã[]ãšãããªãã¬ãŒã¿ãã©ãã
ãæå³ã«ããããšãã話ã§ããä»ã®ïŒ£ãšåãã§äžã®ãããªæå³ã§ã
ãããããªãã§ããã
In article <3FC984FF...@jcom.home.ne.jp>
Shinobu Kumaoka <tito...@jcom.home.ne.jp> writes:
> pc1=&c[0];
> ãšãæ瀺çã«æžããŸããããšããããšã§ã¯ã
ã¯ããããã okãäžã«æžããããã«ãã£ã¹ãã okã
> æŽå²ã®ifãæ€èšŒããã®ã¯é¢çœãã§ãããåœæã®äºæ
ãç解ã§ããŸããã
> ä»ã®ä»æ§ãããã»ã©ãã¡ãªãã®ã ãšãç§ã¯æããŸããã
ç§ã¯æªæ¥ã®è©±ã奜ãã§ãã
main() ã®åŒæ°ã® argv ã§ããããããããªå®£èšã®ä»æ¹ããããŸãã
char **argv ;
char *argv[] ;
char argv[][] ;
ããæåŸã®ãã®é§ç®ãªãã ãã©ãããããã¡ããšèª¬æã§ããã°ã倧
ãããã®ã ãšæããŸãã誰ã説æããŠã¿ãŸãããïŒ
> çŽåŸã§ããæ²³éãããæããããäŸã¯ãtypedefã䜿çšããçç±ã®ïŒã€ã«ã¯å¯èªæ§ã
> ããããããã®ãã®ã§ããããç¡æ¡ä»¶ã«typedefã䜿çšãããšç¡çšãªæ··ä¹±ãèµ·ãããš
> ããããäŸã瀺ããããšããããšã§ããã
ãããã¯éã§ãããã
> typedef int (*fnptr)();
> typedef fnptr (*fnptr_fn)();
ãtypedefã䜿ã£ãŠããæžããšå€ãããã
> typedef int (*(*fnptr_fn)())();
ã䜿ããã«ããæžããšãããã«ããâŠâŠãšã
ãã§ã(int (*)())(*)() ã¯åã«é¯èŠã®ç£ç©ãªã®ã§ãããã
ããïŒãã¿ãïŒæ³šïŒç®ããé±ãèœã¡ãé³ãšãã£ãããé³ïŒ
確ãã«ããã§ãããééã£ãŠããŸããã
>
> > typedef int (*fnptr)();
> > typedef fnptr (*fnptr_fn)();
>
> ãtypedefã䜿ã£ãŠããæžããšå€ãããã
>
> > typedef int (*(*fnptr_fn)())();
>
> ã䜿ããã«ããæžããšãããã«ããâŠâŠãšã
ããã§ãããæåããïŒfnptr_fnã®æ¹ã¯ã©ããªåãã€ã¡ãŒãžã§ããã®ã§ããïŒ(int
(*)())(*)()ãšã®é¢ä¿ã§ïŒé ã®äžãé転ããŠãªããåãã®ããããæç« ã«ãªã£ãŠã
ãŸã£ãããã§ãã
> ãã§ã(int (*)())(*)() ã¯åã«é¯èŠã®ç£ç©ãªã®ã§ãããã
ã§ããããšããã§ïŒ(int (*)())(*)()ã£ãŠè¡šèšã¯æå³çã«ã¯éãããã§ããïŒææ³ç
ã«ã¯ãšã©ãŒã§ããããïŒãŸãïŒééã£ãããšãèšã£ãŠããããç¥ããŸããããïŒ
> > int (*(*ptr1)())();
ãããptr1 ãæ¶ãã°ãint (*(*)())(); ãšãªããããªã®ã§ãéé
ãããããªããããªãã§ãã... ããããä»çµã¿ã ãšæ°ä»ããŸã§ã¯ã
ãã£ã±ãããã§ãããã*ãã()ã®æ¹ãçµåã匷ãã®ã§()ãããã
ãšãèšãããããã ãã©ã
In article <bqfftt$f3n$1...@news511.nifty.com>, <koun...@mbh.nifty.com> writes
> ã§ããããšããã§ïŒ(int (*)())(*)()ã£ãŠè¡šèšã¯æå³çã«ã¯éãããã§ããïŒææ³ç
> ã«ã¯ãšã©ãŒã§ããããïŒãŸãïŒééã£ãããšãèšã£ãŠããããç¥ããŸããããïŒ
ã©ãã«èå¥åãããããã£ãŠããšãªãã§ããã©ã...
% gcc -c tmptmp.c
tmptmp.c:1: error: parse error before "int"
ãšããããªããbefore ãªã®ããã
int j;
int (*(*k)())();
k = (int (*(*)())()) j;
ã¯ãéããã ãã©ã
int (*(*)())() j;
ã¯éããªãã§ãããè¯ãåãããããã£ã¹ããšååã¯éããã®ã¿ããã
---
Shinji KONO @ Information Engineering, University of the Ryukyus,
æ²³éçæ²» @ çç倧åŠå·¥åŠéšæ
å ±å·¥åŠç§,
ïŒïŒ²ã®ïŒ°ïŒïŒïŒã«ãïŒâäºæ¬¡å
é
åãé¢æ°ã«æž¡ãå Žåã¯ïŒé¢æ°ã®åŒæ°å®£èšã«ã¯åã®
æ°ããªããã°ãªããªããâãšã¯ã£ããæžãããŠããã®ã§ïŒæåŸã®char argv[][] ã¯é§
ç®ãšç§ãäžãèŠããšãçåãç¡ãçŽåŸããŠãŸãããïŒïŒ¯ïŒ«ã®ããã§ããããšããããš
ã¯ïŒchar argv[][] ã¯äºæ¬¡å
é
åã®ããã«èŠãããïŒåãªããã€ã³ã¿ã®ãã€ã³ã¿ã®ãš
ããããšã§ïŒé
åã§ã¯ãªããšããããšã«ãªãã®ããªããããŸãé¯èŠã®äžçš®ïŒã
<bqgtse$bas$1...@news511.nifty.com>ã®èšäºã«ãããŠ
koun...@mbh.nifty.comããã¯æžããŸããã
kounoike> ïŒïŒ²ã®ïŒ°ïŒïŒïŒã«ãïŒâäºæ¬¡å
é
åãé¢æ°ã«æž¡ãå Žåã¯ïŒ
kounoike> é¢æ°ã®åŒæ°å®£èšã«ã¯åã®æ°ããªããã°ãªããªããâãšã¯ã£ã
kounoike> ãæžãããŠããã®ã§ïŒæåŸã®char argv[][] ã¯é§ç®ãšç§ãäž
kounoike> ãèŠããšãçåãç¡ãçŽåŸããŠãŸãããïŒïŒ¯ïŒ«ã®ããã§ããã
ã? OK ã£ãŠã©ãããæå³ã§ãã?
Java ãããªãã®ã§, ã¡ãããšãšã©ãŒã«ãªãã¯ãã§ãã.
# C# ã§ããããã ã£ã?
main ã®å®£èšãšã㊠ISO C ã§èŠå®ãããŠããã®ã¯
int main(void)
ãš
int main(int argc, char **argv)
ã® 2ã€ã ãã§ã (char **env ãè¿œå ã§ããåŠçç³»ããã). ããã§
char **argv ãš char *argv[] ãå®ã¯äºæãªã®ã§
int main(int argc, char *argv[])
ãšãæžãããšããã ãã®è©±ã§ããã.
# ã§, char *argv[] ãš char argv[][] 㯠(ã³ã³ãã€ã«ãšã©ãŒã«ãªãç¹
# ãå·®ãåŒããŠã) äºæãããªã.
kounoike> ãšããããšã¯ïŒchar argv[][] ã¯äºæ¬¡å
é
åã®ããã«èŠãã
kounoike> ãïŒåãªããã€ã³ã¿ã®ãã€ã³ã¿ã®ãšããããšã§ïŒé
åã§ã¯ãª
kounoike> ããšããããšã«ãªãã®ããªããããŸãé¯èŠã®äžçš®ïŒã
宣èšã«ãããŠ, ãé
åããšããã€ã³ã¿ãã¯å¥ãã®ã§ã. ãããåå.
äœã, é¢æ°ã®ä»®åŒæ°ãªã¹ãã«ãããŠã¯ (é
åãé¢æ°ã«æž¡ããšãã«ãã€ã³
ã¿ã«å€æããããã) é
åã®åœ¢åŒã§æžããŠããã€ã³ã¿ãšããŠè§£éãããŸ
ã.
--
åå€å±å€§åŠå€§åŠé¢ æ
å ±ç§åŠç ç©¶ç§ èšç®æ©æ°çç§åŠå°æ»
å°é åç·
ãã£ããŸãããŠãïŒå€ãªããšãæžããŠããŸã£ãã®ãããŸãïŒãé°ã§è²ã
å匷ã«ãªãã
ã¡ãã¯æãé£ãã®ã§ããïŒåšãã«ã¯è¿·æããšãšæããŸããã
ã§ïŒïŒ¯ïŒ«ãšæžããã®ã¯ïŒåã«
int hoge(char argv[][]);
ãã³ã³ãã€ã«ã§ããã®ã§åçŽã«ïŒ¯ïŒ«ã§ã¯ãšæã£ã次第ã§ããïŒéãã®ããªã
gcc version 3.1.1ã䜿çšããŸããã
> Java ãããªãã®ã§, ã¡ãããšãšã©ãŒã«ãªãã¯ãã§ãã.
> # C# ã§ããããã ã£ã?
>
> main ã®å®£èšãšã㊠ISO C ã§èŠå®ãããŠããã®ã¯
äžã®è©±ã¯ãmainã«éã£ã話ã§ã¯ãªãã§ããããåã«ãé¢æ°ã®åŒæ°ã«char argv[][]ãš
èšã£ãé¡ã®è¡šèšããã©ããã®è©±ãšæã£ãŠãã®ã§ããããªããåéãããŠããã®ã
ãªã
ããŸã£ã.
<bqhkot$m9r$1...@news511.nifty.com>ã®èšäºã«ãããŠ
koun...@mbh.nifty.comããã¯æžããŸããã
kounoike> ã§ïŒïŒ¯ïŒ«ãšæžããã®ã¯ïŒåã«
kounoike> int hoge(char argv[][]);
kounoike> ãã³ã³ãã€ã«ã§ããã®ã§åçŽã«ïŒ¯ïŒ«ã§ã¯ãšæã£ã次第ã§ããïŒéãã®ããªã
ãISO Cããå€ãã£ããã ã£ã.
C89 (åã®ããŒãžã§ã³) ã§ã¯ã¢ãŠãã§ãã, C99 (æ°ããããŒãžã§ã³) ã§
ã¯ã§ããããã«ãªã£ã... ã®ããª? èŠæ Œãèªãã§ããããããã.
T [] 㯠imcomplete type ã ãã, ããã䜿ã£ã T [][] ã¯ã¢ãŠãã®ã
ããªæ°ããããã ã.... ã©ãã䜿ããªããšãšã©ãŒã«ãªããªãããã .
äžã«ç€ºãäŸã§ã¯ gcc ã§ããšã©ãŒã«ãªããã ãã©....
kounoike> > main ã®å®£èšãšã㊠ISO C ã§èŠå®ãããŠããã®ã¯
kounoike> äžã®è©±ã¯ãmainã«éã£ã話ã§ã¯ãªãã§ããããåã«ãé¢æ°ã®åŒæ°ã«char argv[][]ãš
kounoike> èšã£ãé¡ã®è¡šèšããã©ããã®è©±ãšæã£ãŠãã®ã§ããããªããåéãããŠããã®ã
kounoike> ãªã
C99 ã«ãªã£ãŠ, gcc ã®æ¡åŒµæ©èœãããªãåã蟌ãŸãããã§ããã....
# ã§ãæ©èœã倧ãããªããããã®ã§, gcc ã§ãå®å
šã«ã¯å¯Ÿå¿ã§ããŠãªã.
äŸ:
-------------------- ãããã --------------------
#include <stdio.h>
int main(int argc, char argv[][])
{
for (int i = 0; argv[i] != 0; i++) {
printf("argv[%d] = `%s'.\n", i, argv[i]);
}
return 0;
確ãã«ãargvãé¢æ°ã®äžã§å€åããããã®ã¯ãã¡ã§ããã
ãŸããåœç¶ã®ãããªæ°ãããŸããå°éãããåã®èšäºã®äžã§,â char *argv[] ãš
char argv[][] 㯠(ã³ã³ãã€ã«ãšã©ãŒã«ãªãç¹ãå·®ãåŒããŠã) äºæãããªã.âãš
èšãããŠããããåœç¶ããã€ã³ã¿ã®ãã€ã³ã¿ãïŒæ¬¡å
é
åãšåããªãããã§ããªã
ãã
ããããé
åã®äžå®å
šã¿ã€ãã®åŒæ°ã§ããã®åŒæ°ãå€åãããªããã°äžæè°ãšãšã©ãŒ
ã«ãªããªãã®ãããŸãäžæè°ãªæ°ãããŸããäŸãã°ã次ã®ãã€ã¯ãšã©ãŒãªãåããŸã
ãã
ïŒæ··ä¹±ããŠããã®ã§ããã®åé¡ã®äŸãšããŠé©åãªã®ãã©ããããåãããŸããïŒ
#include <stdio.h>
int main()
{
char p[][10]={"abc","def"};
char (*pp)[10];
char * hoge(char[][]);
pp = p;
pp++;
printf("p[0][10] = %s\n", hoge(p));
printf("p[1][10] = %s\n", hoge(pp));
return 0;
}
char * hoge(char s[][])
{
return *s;
ãïœã, ãªããã¡ãã£ãšèŠããŠãããããª....
<bqhut3$d2b$1...@news511.nifty.com>ã®èšäºã«ãããŠ
koun...@mbh.nifty.comããã¯æžããŸããã
kounoike> char * hoge(char s[][])
kounoike> {
kounoike> return *s;
kounoike> }
ãã,
return *s;
ã
return s[0];
ã«ãããšãšã©ãŒã«ãªããŸã. ã©ããåé
ã® * ã ãç¹å¥èŠããŠããããã.
# é çã....
ç¬ãèšïŒ
åŒæ°ã«char a[][]ã¿ãããªãã®ã䜿çšã§ããŠãïŒaã®å€ãå€æŽã§ããªããã°ãªãã®ã¡
ãªããããªãïŒãªãã®ããã«ããã®ããªããšä»ãçåã«æã£ãŠããŸããïŒæ¬¡ã®ãããª
䜿ãæ¹ãã§ããã®ããªãšããã ïŒéãã§ããã
#include <stdio.h>
int main()
{
char p[][10]={"abc", "def"};
char pp[][5]={"ABC", "DEF", "HIJ"};
int i;
char * hoge(char[][], int, int);
for(i = 0; i < 2; i++)
printf("p[%d][10] = %s\n", i, hoge(p, i, 10));
for(i = 0; i < 3; i++)
printf("pp[%d][5] = %s\n", i, hoge(pp, i, 5));
return 0;
}
char* hoge(char s[][], int m, int n)
{
char (*pp)[n];
pp = s;
pp = pp + m;
return (char *)pp;