LinuxÒÁµéÔ°ÂÛ̳'s Archiver

souldump ·¢±íÓÚ 2006-3-21 09:09

ÈçºÎʹÓÃattributeÊôÐÔ£¿

ÎÒÔںü¸±¾ÊéÖп´µ½ÓÐʹÓÃÊôÐԹؼü×Ö__attribute__µÄ´úÂ룬×Ô¼ºÐ´Á˸öÒ²£¬¿ÉϧÔõôҲ²»ÄÜͨ¹ý±àÒ룬˵ÎÞ·¨Ê¶±ð£¬±»ºöÂÔ£¬ÊDz»ÊÇÒªÔÚ±àÒëµÄʱºò¼ÓÑ¡Ïî°¡£¬ÓÐÖªµÀµÄÅóÓѰï¸öæ°¡£¬Ð»Ð»ÁË£¡

dearvoid ·¢±íÓÚ 2006-3-21 09:15

one example:[code][color=blue]-(user@host:tty)-(syntax)-
5Y;Y%eo VDb3h [3768 0] $ [/color]cat attribute.constructor.c:[a ~%m&B-S2e'Dn%s
/*
Pav]h`#K5R * Author: <dearvoid AT 263 DOT net>
.pE:eh5v *
.h m h9g4Ly-L*dW"LE-} * $Date: 2006-03-13 09:50:30 +0800 (Mon, 13 Mar 2006) $DW&JO$|@
* $HeadURL: svn://jwang/repos/trunk/void/c/syntax/attribute.constructor.c $(JC2[)s+xY,wz X+q7J
* $Revision: 34 $
l!E3Ez~'b,X */Z+p,}:N} DstYf
H5cfn.c*LpC B7l+N%b
#include <stdio.h>x*~*zp*X2t!_dZ

s;oLq(Gr].x,M void start_up(void) __attribute__(( constructor ));B4w\JS7{'n!q
void clean_up(void) __attribute__(( destructor ));
;f;X4U~gPnaGN/m H8g B*E5Y;MR8iV3M
void start_up(void)6~.N,Fg!`d
{c3OT#`"OO8k%^ z
    printf("Now in constructor\n");?;ceA*s#pl
}
?"bE ^{v
.y&~b_$U1A3F9dm void clean_up(void)
;r3j R&o)b/~ {
,L5Cu s1]%N     printf("Now in destructor\n");
4ACM fm };z5n u&Y(i#m
I_0}rk
int main()
hyM/O T*{:a {
V%~+q-]ZC_\"mw Z     return 0;w4THEW ps2F
}
|wh+VVd1x;oq'[ [color=blue]-(user@host:tty)-(syntax)- e9ek6xC I A
[3768 0] $ [/color]gcc attribute.constructor.c -o attribute.constructor
KU:BU1U wM [color=blue]-(user@host:tty)-(syntax)-
E6Vc,AC9vM,l [3768 0] $ [/color]./attribute.constructor0q.Emc7r} Y1B%|
Now in constructor)X.VD{a7?FJ
Now in destructor
i M4R+f} [color=blue]-(user@host:tty)-(syntax)-
,HH-T UJp[)qR [3768 0] $ [/color][/code]

flag ·¢±íÓÚ 2006-3-21 09:53

´ó¸ÅËÑÁËһϣ¬__attribute__µÄÒâ˼£¬¿ÉÒÔΪº¯Êý£¨Function Attributes£©£¬±äÁ¿£¨Variable Attributes£©ºÍ½á¹¹³ÉÔ±£¨Type Attributes£©¸³ÊôÐÔ¡£Â¥ÉϵÄÀý×ÓÓ¦¸ÃÊǸøº¯ÊýÓõġ£

souldump ·¢±íÓÚ 2006-3-24 22:03

¶¼¿ÉÒÔÓã¬ÎÒÒ²ÊÇÄãÄÇôдµÄ£¬¿ÉÊDZàÒëÆ÷¾ÍÊÇͨ²»¹ý£¬×Ü˵ÎÞ·¨Ê¶±ð¹Ø¼ü×Ö°¡
b9p$pT.b4{7b R M ²»¹ý»¹ÊÇллÁË£¬ÎÒÔÙÊÔÏÂ

Ò³: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.