[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] Hvor starter man



"Egon Petersen" <sslug@sslug> writes:

> Så lavede jeg et simpelt Hello World program med en printf(), og jeg fik en
> warning om main og return der ikke hang sammen, selv om jeg havde lavet en
> return sætning til sidst.

Det ville hjælpe hvis du skrev præcis hvad du gjore og hvad du fik.

bash-2.05b$ cat > fooo.c
#include<stdio.h>

void main() {
   printf("Hello World\n");
   return 0;
}
bash-2.05b$ gcc foo
foobar     foobar.cc  foobar.pl  fooo.c     foopah.pl  
bash-2.05b$ gcc fooo.c 
fooo.c: In function `main':
fooo.c:5: warning: `return' with a value, in function returning void
fooo.c:3: warning: return type of `main' is not `int'
bash-2.05b$ 

Problemet herover er at jeg definerer main til at returnerer en void
og jeg lader den returnerer en int. Det er selvfølgelig klart forkert.

Retter jeg det til virker det uden warnings:

bash-2.05b$ cat fooo.c 
#include<stdio.h>

int main() {
   printf("Hello World\n");
   return 0;
}
bash-2.05b$ gcc fooo.c 
bash-2.05b$ ./a.out 
Hello World
bash-2.05b$ 

> Men jeg står stadig og kan ikke se fordelen ved at skifte til C på Linux. Et
> simpelt program kan ikke køre uden warning, der er ingen særlig god editor,
> hvor får man hjælp? Ja jeg kunne blive ved lidt endnu.

Hvis dit simple program ikke er korrekt skrevet ifølge standarden er
det klart du får en warning.

Der er masser af gode editore. Jeg bruger primært cat, vi eller
Emacs. Men jeg bruger dem som editore og ikke som IDE'er, hvis det i
virkeligheden er det du ønsker.

-- 
 Peter Makholm     |      I laugh in the face of danger. Then I hide until
 sslug@sslug |                                          it goes away
 http://hacking.dk |                                             -- Xander


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 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] *