C (itan Re: Ligo asxeto ...)

Giorgos Keramidas keramida at hades.hell.gr
Wed Sep 29 01:51:28 EEST 1999


Se auto atermono thread me tnv C prepei epitelous va paro to aima mou piso :P

D.A.Glynos wrote:
| > Vassilh , den katalava kala to argument sou.
| > Uponoeis oti to parakatw den tha mas kanei print to noumero 2000 ?
| > 
| > int main(){
| >   int a, b[3], *c;
| > 
| >   printf("The size of our integers is %i\n",sizeof(a));
| >   b[0]=1000;
| >   b[1]=2000;
| >   b[2]=3000;
| >   c=b;
| >   printf("The second element of the array is %i\n",*(++c));
| >   return;
| > };

Nai kai oxi.  Nai tuponei 2000, oxi den einai swsto san programma, giati
bgazei ta ekshs:

    % gcc -Wall try.c -o try
    try.c: In function `main':
    try.c:5: warning: implicit declaration of function `printf'
    try.c:11: warning: `return' with no value, in function returning non-void

| Αυτό βεβαίως και θα τυπώσει 2000. Το ίδιο επίσης θα τυπώσει αν
| αντικαταστήσεις το `++c' με το `c+1' ή και με το `c+=1'. Αν όμως το
| αντικαταστήσεις με το `c+=sizeof(int)' που υποστήριξε ο Γιώργος ότι είναι
| ισοδύναμο, το αποτέλεσμα που θα πάρεις θα είναι πολύ διαφορετικό...

Tha tuposei 2000 epeidn to `c' einai dnlwmevo sav (int *) ki edo ntav n
mal.*ia pou egrapsa ego se prongoumevo posting, giati egrapsa (int *) kai
skeftomouna me (void *) stnv opoia periptosi to sizeof(int) xreiazetai,
giati to (void *) den exei megethos kai prepei na grapseis kati san:

	int b[3];
	void *c;	/* prosoxi (void *) ki oxi (int *) */
	
        c = (int *) b;
        printf("The second element of the array is %i\n",
	       *( (int *) (c += sizeof(int)) );

H akoma (an kaneis to casting se (int *) prin to ++ operator) mporeis na
grapseis kati san:

        c = b;
        printf("The second element of the array is %i\n",
               *(++((int *)c)) );

Alla tote einai san na grafeis se Lisp ki oxi se C... frikn dnladn, giati n
Lisp mporei na exei apeires parev0eseis, alla exei ki eva garbage collection
anotero opws kai na to kanoume.  Enw stn C sou feugei mia paren0esn kai mazi
sou feugei ki ena Mb mvnmns, pikra.

                                    * * *

$ps->[0] Die evil thread, die.

$ps->[1] Prepei na ksanadiabaso tn biblo twv K&R akoma mia fora.

$ps->[2] Kai na stamatiso na grafo Perl epitelous.  Ama pia, konteuo na
    ksexaso kai tin ligi C pou ksero.

-- 
Giorgos Keramidas, <keramida at ceid.upatras.gr>
Modem hangu}#}!}!}!} }4}"}&} } } }
pppd: Segmentation fault (core dumped)
--
====================================================================
Gia boithia (h na diagrafhte) e-mail sto majordomo at hellug.gr
Ta archives tis listas einai sto http://lists.hellug.gr/archives
prin steilete kapoia erothsh psakte mipos exei hdh apanththei.
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users at hellug.gr
====================================================================



More information about the Linux-greek-users mailing list