[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Döda ett program i en funktion??



Johan Andersson wrote:
> > void bla(void)
> > {
> >         printf("haha\n");
> >         main();
> >
> > }
> >
> > int main(int argc, char **argv)
> > {
> >         atexit(&bla);
> >         exit(0);
> > }
> >
> 
> Jag är, som sagt, ny på c++-programmering. Vad är det du gör här?? &-tecknet menar jag...

Eksemplet var bare for at drille Morten lidt. Men &-tegnet giver
dig adressen på en funktion (eller en variabel, for den sags
skyld). atexit() forventer en pointer til en funktion som
argument.

atexit() markerer funktioner til eksekvering ved et exit()
kald. Derfor vil ovenstående kode ikke terminere efter
exit() kaldet, men derimod skrive 'haha' på terminalen,
kalde main() og så kører løkken.

Ellers er ovenstående nu C, selvom det også er valid C++.

-- 
*  Jens Axboe <sslug@sslug>
*  Linux CD-ROM Maintainer
* "The only thing that interferes with my
*  learning is my education." -- A. Einstein


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *