[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] Hvad går der galt?



On Thu, 06 Nov 2003 12:01:57 +0100
Carsten Svaneborg <sslug@sslug> wrote:

> Egon Petersen wrote:
> > Det sjove er at kildeteksten faktisk virker i Visual C++ 6.0.
> > Imponerende.

Hvad var det helt nøjagtigt, som virkede?

> Jeg ville nu sige at det var skræmmende, compileren har nok 
> information til at vide at du forsøger at bruge et element uden
> for det allokerede array, og burde mindst give dig en warning.

Visual C++ kan også give warnings i flere levels.

> Btw. ligner dit program noget der langt bedrer kunne laves med
> perl. Strengbehandling i C (og C++) er ren masochisme. Og den
> tid det tager at debugge coredumps pga. +1 fejl, er bedrer
> brugt på at lære perl.

Når Egon nu spørger pænt om C string handling, så synes jeg lige
at man skal sige det er ok, ikke det samme som andre sprog,
men i realiteten kan man godt lære det på 3 - 6 måneder, så
det fungerer uden begynderfejl.

Man kan i C sagtens skrive pæn kode som 

    udskriv(maanedsnavn[12])

hvis man er klar over, hvordan maanedsnavn skal erklæres, in casu 

char *maanedsnavn[13] = {
   "Invalid month or internal program error",
   "January",
   "February",
   "March",
   "April",
   "May",
   "June",
   "July",
   "August",
   "September",
   "October",
   "November",
   "December"
};

Smart, ikk'?

Problemet i det eksempel, som den oprindelige spørger kom med,
var at et 2D array blev forkert håndteret, og så synes jeg
i øvrigt at Makholm har påpeget alle de andre fejl, som gjorde
eksemplet til et skoleeksempel på, hvordan man ikke skriver C
kode.






-- 
sslug@sslug -- http://d-axel.dk/


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

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